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}
Answer from hpaulj on Stack Overflow
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.html
numpy.ndarray — NumPy v2.6.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....
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()).

🌐
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.
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...
🌐
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 › 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 › 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]])
🌐
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
🌐
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.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.item.html
numpy.ndarray.item — NumPy v2.1 Manual
ndarray.item(*args)# Copy an element of an array to a standard Python scalar and return it.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Get and set values in an array using various indexing | note.nkmk.me
February 7, 2024 - This article explains how to get and set values, such as individual elements or subarrays (e.g., rows or columns), in a NumPy array (ndarray) using various indexing. Indexing on ndarrays — NumPy v1.2 ...
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray › .all()
Python:NumPy | ndarray | .all() | Codecademy
October 30, 2025 - In NumPy, the .all() method returns True if all elements in an ndarray evaluate to True, or if all elements along a specified axis evaluate to True. The .all() method can operate on the entire array to check if all values are truthy, or work along specific axes to perform row-wise or column-wise boolean validation.
🌐
Machine Learning Plus
machinelearningplus.com › blog › numpy tutorial – your first numpy guide to build python coding foundations
Python NumPy - Introduction to ndarray [Must Read Tutorial]
March 15, 2026 - It works like Python’s range, but returns an ndarray: import numpy as np print("Default (0 to 4):", np.arange(5)) print("0 to 9:", np.arange(0, 10)) print("0 to 9, step 2:", np.arange(0, 10, 2)) print("10 to 1, decreasing:", np.arange(10, 0, -1)) With np.arange, you set the start, stop, and step. But what if you want exactly N numbers between two values?