🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v2.5.dev0 Manual
class numpy.ndarray(shape, dtype=np.float64, buffer=None, offset=0, strides=None, order=None)[source]#
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v2.1 Manual
Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array. For more information, refer to the numpy module and examine the methods and attributes of an array.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v2.4 Manual
Default is numpy.float64. ... Used to fill the array with data. ... Offset of array data in buffer. ... Strides of data in memory. ... Row-major (C-style) or column-major (Fortran-style) order. ... Construct an array. ... Create an array, each element of which is zero. ... Create an array, but leave its allocated memory unchanged (i.e., it contains “garbage”). ... Create a data-type. ... An ndarray alias generic w.r.t.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.item.html
numpy.ndarray.item — NumPy v2.2 Manual
ndarray.item(*args)# Copy an element of an array to a standard Python scalar and return it.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.item.html
numpy.ndarray.item — NumPy v2.4 Manual
ndarray.item(*args)# Copy an element of an array to a standard Python scalar and return it.
🌐
W3Schools
w3schools.com › python › numpy › numpy_creating_arrays.asp
NumPy Creating Arrays
To create an ndarray, we can pass ... as their elements. 0-D arrays, or Scalars, are the elements in an array. Each value in an array is a 0-D array....
🌐
NumPy
numpy.org › doc › stable › reference › arrays.ndarray.html
The N-dimensional array (ndarray) — NumPy v2.4 Manual
Arithmetic and comparison operations on ndarrays are defined as element-wise operations, and generally yield ndarray objects as results. Each of the arithmetic operations (+, -, *, /, //, %, divmod(), ** or pow(), <<, >>, &, ^, |, ~) and the comparisons (==, <, >, <=, >=, !=) is equivalent to the corresponding universal function (or ufunc for short) in NumPy. For more information, see the section on Universal Functions. ... Truth-value testing of an array invokes ndarray.__bool__, which raises an error if the number of elements in the array is not 1, because the truth value of such arrays is ambiguous.
Top answer
1 of 3
2

When you save a Python object (non-array), numpy wraps it in an array. The object is pickled:

In [112]: np.save('test.npy', {'foo':34})                                              

In newer numpy versions, you have to explicitly allow it to load pickled items:

In [113]: data = np.load('test.npy')                                                   
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-113-c5835e6fb31e> in <module>
----> 1 data = np.load('test.npy')

/usr/local/lib/python3.6/dist-packages/numpy/lib/npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
    451             else:
    452                 return format.read_array(fid, allow_pickle=allow_pickle,
--> 453                                          pickle_kwargs=pickle_kwargs)
    454         else:
    455             # Try a pickle

/usr/local/lib/python3.6/dist-packages/numpy/lib/format.py in read_array(fp, allow_pickle, pickle_kwargs)
    720         # The array contained Python objects. We need to unpickle the data.
    721         if not allow_pickle:
--> 722             raise ValueError("Object arrays cannot be loaded when "
    723                              "allow_pickle=False")
    724         if pickle_kwargs is None:

ValueError: Object arrays cannot be loaded when allow_pickle=False


In [115]: data = np.load('test.npy',allow_pickle=True)                                 
In [116]: data                                                                         

The result is an object dtype array with 1 element (0d)

Out[116]: array({'foo': 34}, dtype=object)

tolist can extract that object, as will item().

In [117]: data.tolist()                                                                
Out[117]: {'foo': 34}
In [118]: data.tolist()['foo']                                                         
Out[118]: 34
In [119]: data.item()                                                                  
Out[119]: {'foo': 34}
In [120]: data[()]                                                                     
Out[120]: {'foo': 34}
2 of 3
0

That looks like a dictionary, rather than an ndarray. Assuming you don't have multiple keys associated with the same value, you reverse the dictionary with

la_reversed = {v: k for k, v in la.items()}

so la_reversed[0] would be 'val1' and la_reversed[1] would be 'val2'.

You can get a list of values in the dictionary with list(la.values()).

Find elsewhere
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v2.3 Manual
Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array. For more information, refer to the numpy module and examine the methods and attributes of an array.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.array.html
numpy.array — NumPy v2.4 Manual
If not given, NumPy will try to ... the values (by applying promotion rules when necessary.) ... If True (default), then the array data is copied. If None, a copy will only be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.). Note that any copy of the data is shallow, i.e., for arrays with object dtype, the new array will point to the same objects. See Examples for ndarray.co...
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-ndarray
Numpy - ndarray - GeeksforGeeks
July 26, 2025 - ndarray is a short form for N-dimensional array which is a important component of NumPy. It’s allows us to store and manipulate large amounts of data efficiently. All elements in an ndarray must be of same type making it a homogeneous array.
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray
Python:NumPy | ndarray | Codecademy
August 24, 2025 - The following example creates an ndarray and performs several operations on it. ... Returns True if all elements in the array evaluate to True, or along a specified axis. ... Returns the indices of the maximum values along a specified axis. ... Converts a NumPy array to a specified data type.
🌐
NumPy
numpy.org › doc › 1.18 › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v1.18 Manual
May 24, 2020 - >>> np.ndarray(shape=(2,2), dtype=float, order='F') array([[0.0e+000, 0.0e+000], # random [ nan, 2.5e-323]])
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v2.2 Manual
Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array. For more information, refer to the numpy module and examine the methods and attributes of an array.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.view.html
numpy.ndarray.view — NumPy v2.4 Manual
>>> x = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int16) >>> y = x[:, ::2] >>> y array([[1, 3], [4, 6]], dtype=int16) >>> y.view(dtype=[('width', np.int16), ('length', np.int16)]) Traceback (most recent call last): ... ValueError: To change to a dtype of a different size, the last axis must be contiguous >>> z = y.copy() >>> z.view(dtype=[('width', np.int16), ('length', np.int16)]) array([[(1, 3)], [(4, 6)]], dtype=[('width', '<i2'), ('length', '<i2')])
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v2.0 Manual
>>> np.ndarray(shape=(2,2), dtype=float, order='F') array([[0.0e+000, 0.0e+000], # random [ nan, 2.5e-323]])
🌐
GeeksforGeeks
geeksforgeeks.org › python-numpy-ndarray-item
Python | Numpy ndarray.item() | GeeksforGeeks
March 27, 2019 - Syntax: ndarray.__ipow__($self, value, /) Return: self**=value Example #1 : In this example we can see that every element get powe ... With the help of Numpy ndarray.__ixor__() method, we can get the elements that is XOR by the value that is provided as a parameter in numpy.ndarray.__ixor__() method.
🌐
SciPy
docs.scipy.org › doc › numpy-1.14.0 › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v1.14 Manual
>>> np.ndarray(shape=(2,2), dtype=float, order='F') array([[ -1.13698227e+002, 4.25087011e-303], [ 2.88528414e-306, 3.27025015e-309]]) #random
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.view.html
numpy.ndarray.view — NumPy v2.2 Manual
>>> x = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int16) >>> y = x[:, ::2] >>> y array([[1, 3], [4, 6]], dtype=int16) >>> y.view(dtype=[('width', np.int16), ('length', np.int16)]) Traceback (most recent call last): ... ValueError: To change to a dtype of a different size, the last axis must be contiguous >>> z = y.copy() >>> z.view(dtype=[('width', np.int16), ('length', np.int16)]) array([[(1, 3)], [(4, 6)]], dtype=[('width', '<i2'), ('length', '<i2')])