llohse / libnpy

C++ library for reading and writing of numpy's .npy files
MIT License
361 stars 72 forks source link

"'std::runtime_error' what(): formatting error: typestrings not matching", #26

Closed coreeey closed 1 day ago

coreeey commented 2 years ago

I find i can't load the numpy file due to "terminate called after throwing an instance of "'std::runtime_error' what(): formatting error: typestrings not matching", and i tried "std::vector<std::complex> data", std::vector<std::complex> data, std::vector data, std::vector data and so on, it didn't work too, the size of my numpy file is (1, 25, 224,224). here is my code: npy::LoadArrayFromNumpy("00000_1_video.npy", video.shape, video.fortran_order, video.data);

coreeey commented 2 years ago

I convert my numpy file to float and i can copy the d.data, but d.fortran_order is '0', so does it mean that i load the file incorrectly?

llohse commented 2 years ago

This error message could use some improvement.

Do you know what format your original file was in? What does hexdump -C -n 80 <filename> give you?

fortran_order indicates if the data is column-major (fortran order = True) oder row-major (fortran order = False), so it being 0 could be perfectly correct in many cases.

LamForest commented 2 years ago

This error maybe because your ndarray type doesn't match c++ std::vector 's type.

You can set ndarray type by np.save(f, array.astype(np.float32))

llohse commented 1 day ago

Closing because of inactivity