np.load of np.savez impossible to get values back out?
jensroth-git opened this issue · 3 comments
jensroth-git commented
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 commented
Can you give a a similar python code so I can test and compare?
MrC0rrupted commented
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 commented
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);
}