ValueError: Object arrays cannot be loaded when allow_pickle=False in Python

Dung Do Tien Sep 04 2021 37

Hello Guys, In Python 3.8.2 I try to load a file by using numpy package. 

Like this:

import numpy as np

When run code I get an exception ValueError: Object arrays cannot be loaded when allow_pickle=False.

ValueError Traceback (most recent call last)
<ipython-input-37-1db66562b57b> in <module>
----> 1 np.load('tmp.npy')

~/venv/aep/lib/python3.8.2/site-packages/numpy/lib/ 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

~/venv/aep/lib/python3.8.2/site-packages/numpy/lib/ 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

My environment:

Python: 3.8.2

Numpy: 1.16.3

Thanks for any suggestions.

Have 1 answer(s) found.
  • H

    Huỳnh Ngọc Thiện Sep 04 2021

    Maybe you did not check parameter change by version. The numpy.load()the behavior of the function has changed.

    load() method has two params are path_file and allow_pickle.  With the old version allow_pickle has a default value for it is True and in the new version allow_pickle set default to false.

    So to solve the issue ValueError: Object arrays cannot be loaded when allow_pickle=False you can do as below:

    import numpy as np
    np.load('/path/data/students.npy', allow_pickle=True)

    I hope it solve for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close