Guest User

Untitled

a guest
Jan 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {
  7. "collapsed": true
  8. },
  9. "outputs": [],
  10. "source": [
  11. "import numpy as np\n",
  12. "from tqdm import tqdm"
  13. ]
  14. },
  15. {
  16. "cell_type": "code",
  17. "execution_count": 2,
  18. "metadata": {},
  19. "outputs": [],
  20. "source": [
  21. "def calc_meanstd(groups):\n",
  22. " means = [np.mean(x) for x in groups]\n",
  23. " mean = np.mean(means)\n",
  24. " meanstd = 0\n",
  25. " for i in means:\n",
  26. " meanstd+=np.abs(i-mean)\n",
  27. " return float(meanstd)\n",
  28. "def split_group(group, split_num, number):\n",
  29. " result = []\n",
  30. " for i in range(split_num):\n",
  31. " result.append(group[i*number:(i+1)*number])\n",
  32. " return result\n",
  33. "def make_group(group_list, split_num, try_num):\n",
  34. " print('人数:',len(group_list),'分割数:',split_num)\n",
  35. " if len(group_list)%split_num!=0:\n",
  36. " print('均等に割り切れません')\n",
  37. " return 0\n",
  38. " group_num = int(len(group_list)/split_num)\n",
  39. " \n",
  40. " result = {}\n",
  41. " for _ in tqdm(range(try_num)):\n",
  42. " np.random.shuffle(group_list)\n",
  43. " tmp_result = split_group(group_list,split_num,group_num)\n",
  44. " result[calc_meanstd(tmp_result)] = tmp_result\n",
  45. " sort_result = sorted(result.items())\n",
  46. " return sort_result[0]"
  47. ]
  48. },
  49. {
  50. "cell_type": "code",
  51. "execution_count": 3,
  52. "metadata": {},
  53. "outputs": [
  54. {
  55. "name": "stdout",
  56. "output_type": "stream",
  57. "text": [
  58. "人数: 24 分割数: 3\n"
  59. ]
  60. },
  61. {
  62. "name": "stderr",
  63. "output_type": "stream",
  64. "text": [
  65. "100%|█████████████████████████████████| 10000/10000 [00:00<00:00, 16167.84it/s]\n"
  66. ]
  67. }
  68. ],
  69. "source": [
  70. "a=make_group(list(range(1,25)),3, 10000)"
  71. ]
  72. },
  73. {
  74. "cell_type": "code",
  75. "execution_count": 4,
  76. "metadata": {},
  77. "outputs": [
  78. {
  79. "data": {
  80. "text/plain": [
  81. "array([100, 100, 100])"
  82. ]
  83. },
  84. "execution_count": 4,
  85. "metadata": {},
  86. "output_type": "execute_result"
  87. }
  88. ],
  89. "source": [
  90. "np.sum(a[1], axis=1)"
  91. ]
  92. },
  93. {
  94. "cell_type": "code",
  95. "execution_count": 5,
  96. "metadata": {},
  97. "outputs": [],
  98. "source": [
  99. "test = [8, 9, 9, 3, 5, 8, 9, 9, 8, 10, 10, 10, 9, 10, 10, 10, 6, 7, 10, 9, 10]"
  100. ]
  101. },
  102. {
  103. "cell_type": "code",
  104. "execution_count": 6,
  105. "metadata": {},
  106. "outputs": [
  107. {
  108. "name": "stdout",
  109. "output_type": "stream",
  110. "text": [
  111. "人数: 21 分割数: 3\n"
  112. ]
  113. },
  114. {
  115. "name": "stderr",
  116. "output_type": "stream",
  117. "text": [
  118. "100%|███████████████████████████████| 100000/100000 [00:06<00:00, 16259.33it/s]\n"
  119. ]
  120. },
  121. {
  122. "data": {
  123. "text/plain": [
  124. "(0.1904761904761898,\n",
  125. " [[9, 6, 10, 10, 8, 8, 9], [10, 9, 10, 10, 9, 9, 3], [10, 8, 10, 10, 5, 7, 9]])"
  126. ]
  127. },
  128. "execution_count": 6,
  129. "metadata": {},
  130. "output_type": "execute_result"
  131. }
  132. ],
  133. "source": [
  134. "make_group(test,3, 100000)"
  135. ]
  136. },
  137. {
  138. "cell_type": "code",
  139. "execution_count": null,
  140. "metadata": {
  141. "collapsed": true
  142. },
  143. "outputs": [],
  144. "source": []
  145. }
  146. ],
  147. "metadata": {
  148. "kernelspec": {
  149. "display_name": "Python 3",
  150. "language": "python",
  151. "name": "python3"
  152. },
  153. "language_info": {
  154. "codemirror_mode": {
  155. "name": "ipython",
  156. "version": 3
  157. },
  158. "file_extension": ".py",
  159. "mimetype": "text/x-python",
  160. "name": "python",
  161. "nbconvert_exporter": "python",
  162. "pygments_lexer": "ipython3",
  163. "version": "3.6.1"
  164. }
  165. },
  166. "nbformat": 4,
  167. "nbformat_minor": 2
  168. }
Add Comment
Please, Sign In to add comment