Visitar URL original
np.load of np.savez impossible to get values back out? · Issue #107 · SciSharp/Numpy.NET · GitHub
Skip to content

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

Description

@jensroth-git

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'

Activity

  1. henon commented on Nov 12, 2022

    @henon
    Contributor

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

  2. jensroth-git commented on Nov 12, 2022

    @jensroth-git
    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']))
  3. henon commented on Nov 16, 2022

    @henon
    Contributor

    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);
            }
  4. added a commit that references this issue on Nov 16, 2022
  5. 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?[/+] on Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions