An alternative is to use np.ravel:
>>> np.zeros((3,3)).ravel()
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0.])
The importance of ravel over flatten is ravel only copies data if necessary and usually returns a view, while flatten will always return a copy of the data.
To use reshape to flatten the array:
tt = t.reshape(-1)
Answer from Daniel on Stack OverflowAn alternative is to use np.ravel:
>>> np.zeros((3,3)).ravel()
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0.])
The importance of ravel over flatten is ravel only copies data if necessary and usually returns a view, while flatten will always return a copy of the data.
To use reshape to flatten the array:
tt = t.reshape(-1)
Use .flatten:
>>> np.zeros((3,3))
array([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
>>> _.flatten()
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0.])
EDIT: As pointed out, this returns a copy of the input in every case. To avoid the copy, use .ravel as suggested by @Ophion.
numpy.array is just a convenience function to create an ndarray; it is not a class itself.
You can also create an array using numpy.ndarray, but it is not the recommended way. From the docstring of numpy.ndarray:
Arrays should be constructed using
array,zerosorempty... The parameters given here refer to a low-level method (ndarray(...)) for instantiating an array.
Most of the meat of the implementation is in C code, here in multiarray, but you can start looking at the ndarray interfaces here:
https://github.com/numpy/numpy/blob/master/numpy/core/numeric.py
numpy.array is a function that returns a numpy.ndarray object.
There is no object of type numpy.array.