ndarray.reshape

import numpy as np
a=np.array(range(1,21))
a=a.repeat(6) #repeat(a, repeats[, axis])
print(a)


[ 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5
5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 8 8 9 9
9 9 9 9 10 10 10 10 10 10 11 11 11 11 11 11 12 12 12 12 12 12 13 13 13
13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 16 16 16 17 17 17 17
17 17 18 18 18 18 18 18 19 19 19 19 19 19 20 20 20 20 20 20]


a=a.reshape((20, 6), order=’F’) # ndarray.reshape(shape[, order]) #默认order=”C”按列读取,”F”按行读取
print(a)


[[ 1 4 7 11 14 17]
[ 1 4 7 11 14 17]
[ 1 4 8 11 14 18]
[ 1 4 8 11 14 18]
[ 1 5 8 11 15 18]
[ 1 5 8 11 15 18]
[ 2 5 8 12 15 18]
[ 2 5 8 12 15 18]
[ 2 5 9 12 15 19]
[ 2 5 9 12 15 19]
[ 2 6 9 12 16 19]
[ 2 6 9 12 16 19]
[ 3 6 9 13 16 19]
[ 3 6 9 13 16 19]
[ 3 6 10 13 16 20]
[ 3 6 10 13 16 20]
[ 3 7 10 13 17 20]
[ 3 7 10 13 17 20]
[ 4 7 10 14 17 20]
[ 4 7 10 14 17 20]]


你可能感兴趣的:(numpy,numpy,reshape)