python如何将数组划分为随机大小

时间:2018-12-09 16:03:00

标签: python python-2.7

我想将数组划分为随机大小而不是特定大小。我该怎么办?

B= np.array([[0 ,1, 0,  0,  1,  1,  0,  1,  0,  0],
[1, 0,  1,  1,  0,  1,  0,  1,  1,  0],
[0, 1,  0,  1,  1,  0,  0,  0,  1,  0],
[0, 1,  1,  0,  0,  0,  1,  0,  1,  1],
[1, 0,  1,  0,  0,  1,  1,  0,  1,  0],
[1, 1,  0,  0,  1,  0,  0,  0,  1,  1],
[0, 0,  0,  1,  1,  0,  0,  1,  0,  0],
[1, 1,  0,  0,  0,  0,  1,  0,  0,  1],
[0, 1,  1,  1,  1,  1,  0,  0,  0,  0],
[0, 0,  0,  1,  0,  1,  0,  1,  0,  0]])

new = [2,1,3,5,6,7,9,8]
B1 = np.array([[B[i][j]for j in new] for i in new])

result = []
for _ in xrange(0,5):
      split_ = B1[0:i+1,0:i+1]
      result.append(split_)

0 个答案:

没有答案