How do I create a 0 x 0 (i.e. ndim
= 2, shape
= (0,0)) numpy.ndarray
of float
?
Access Array ElementsThe indexes in NumPy arrays start with 0, meaning that the first element has index 0, and the second has index 1 etc.
NumPy zeros() function is used to create a new array of given shapes and types filled with zero values. The zeros() function takes three arguments and returns the array filled with zeros of floating values by default. We can customize the specific datatype and order by passing these parameters.
>>> import numpy as NP
>>> a = NP.empty( shape=(0, 0) )
>>> a
array([], shape=(0, 0), dtype=float64)
>>> a.shape
(0, 0)
>>> a.size
0
The array above is initialized as a 2D array--i.e., two size parameters passed for shape.
Second, the call to empty is not strictly necessary--i.e., an array having 0 size could (i believe) be initialized using other array-creation methods in NumPy, e.g., NP.zeros, Np.ones, etc.
I just chose empty because it gives the smallest array (memory-wise).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With