Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create 0x0 Numpy array?

Tags:

How do I create a 0 x 0 (i.e. ndim = 2, shape = (0,0)) numpy.ndarray of float?

like image 703
Johan Råde Avatar asked Mar 08 '12 08:03

Johan Råde


People also ask

Do numpy arrays start at 0 or 1?

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.

What is NP zeros in Python?

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.


1 Answers

>>> 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).

like image 86
doug Avatar answered Sep 21 '22 15:09

doug