In order to get a numpy array from a list
I make the following:
np.array([i for i in range(0, 12)])
And get:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
Then I would like to make a (4,3) matrix from this array:
np.array([i for i in range(0, 12)]).reshape(4, 3)
and I get the following matrix:
array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]])
But if I know that I will have 3 * n elements in the initial list
how can I reshape my numpy array, because the following code
np.array([i for i in range(0,12)]).reshape(a.shape[0]/3,3)
Results in the error
TypeError: 'float' object cannot be interpreted as an integer
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…