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

np.load of np.savez impossible to get values back out? #107

Open
jensroth-git opened this issue Nov 12, 2022 · 3 comments
Open

np.load of np.savez impossible to get values back out? #107

jensroth-git opened this issue Nov 12, 2022 · 3 comments

Comments

@jensroth-git
Copy link

after saving some arrays into a .npz archive like so

Dictionary<string, NDarray> arrays = new Dictionary<string, NDarray>();
arrays["valueOne"] = valueOne;
arrays["valueTwo"] = valueTwo;

np.savez_compressed(filename, null, arrays);

its impossible to get the values back out

var archive = np.load(filename);

var valueOne = archive["valueOne"];
var valueTwo = archive["valueTwo"];

it just results in a System.ArgumentException: 'Invalid slice notation'

@henon
Copy link
Contributor

henon commented Nov 12, 2022

Can you give a a similar python code so I can test and compare?

@jensroth-git
Copy link
Author

test_array = np.random.rand(3, 2)
test_vector = np.random.rand(4)
np.savez_compressed('/tmp/123', a=test_array, b=test_vector)
loaded = np.load('/tmp/123.npz')
print(np.array_equal(test_array, loaded['a']))
print(np.array_equal(test_vector, loaded['b']))

@henon
Copy link
Contributor

henon commented Nov 16, 2022

This is not a fix but a workaround

        [TestMethod]
        public async Task IssueByMrCOrrupted()
        {
            Dictionary<string, NDarray> arrays = new Dictionary<string, NDarray>();
            arrays["a"] = np.arange(6).reshape(2, 3);
            arrays["b"] = np.arange(3);

            var filename = Path.Combine(Path.GetTempPath(), "test.npz");
            np.savez_compressed(filename, null, arrays);
            var archive = np.load(filename);
            Console.WriteLine(archive.repr);
            var a = new NDarray( archive.PyObject["a"]);
            var b = new NDarray( archive.PyObject["b"]);
            Console.WriteLine(a.repr);
            Console.WriteLine(b.repr);
        }

henon added a commit that referenced this issue Nov 16, 2022
@henon henon changed the title np.load of np.savez impossible to get values back out np.load of np.savez impossible to get values back out? Nov 16, 2022
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