Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the file format of NumCpp differs from numpy in python? #15

Closed
yujincheng opened this issue May 30, 2019 · 1 comment
Closed

Is the file format of NumCpp differs from numpy in python? #15

yujincheng opened this issue May 30, 2019 · 1 comment

Comments

@yujincheng
Copy link

I dump the array in numpy use a.dump("test.bin"). Yet I can not recover the array in NumCpp with auto a = nc::load("test.bin") .
Is the file format of NumCpp differs from numpy in python?

@dpilger26
Copy link
Owner

dpilger26 commented Jun 2, 2019

Sorry for the confusion. No the file formats are not the same. NumPy uses pickle for its dump/save and load functions. NumCpp writes its arrays in a flat binary format. If you would like to read in a NumCpp dumped file with NumPy then you should use NumPy's fromfile function. eg.

#include "NumCpp.hpp"

int main()
{
    nc::NdArray<nc::int32> a = { {0, -1, -2}, {0, 1, 2}};
    a.dump("C:/Temp/test.bin");
    return 0;
}

Then from python

a = np.fromfile(r'C:\Temp\test.bin', dtype=np.int32).reshape([2,3])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants