If I create an array X = np.random.rand(D, 1), it has the form (3L, 1L):
X = np.random.rand(D, 1)
(3L, 1L)
[[ 0.31215124] [ 0.84270715] [ 0.41846041]]
If I create my own array A = np.array([0,1,2]), then it has a shape (3L,)and looks like
A = np.array([0,1,2])
(3L,)
[0 1 2]
How to force a figure (3L, 1L)in my array A?
A
numpy already has a "reshape" method, which numpy.ndarray.shape you can use to change the shape of your array.
A.shape = (3,1)
A=np.array([0,1,2]) A.shape=(3,1)
or
A=np.array([0,1,2]).reshape((3,1)) #reshape takes the tuple shape as input
numpy reshape, ndarray reshape, :
reshape
import numpy as np A = np.reshape([1, 2, 3, 4], (4, 1)) # Now change the shape to (2, 2) A = A.reshape(2, 2)
Numpy , , .. prod(old_shape) == prod(new_shape). - -1, numpy :
prod(old_shape) == prod(new_shape)
-1
A = A.reshape([1, 2, 3, 4], (-1, 1))
directy i.e.
A.shape = (3L, 1L)
:
A.resize((3L, 1L))
or during creation with a change of form
A = np.array([0,1,2]).reshape((3L, 1L))