Skip to content

Error when loading a .npy file containing a scalar value #517

Closed

Description

@thalesfm

Due to an off-by-one error, np.load fails to parse the file's header when shape = () and triggers an ArgumentOutOfRangeException
(Also, the function doesn't consider this possibility when calculating the size of the underlying buffer).

Activity

  1. Nucs commented on Apr 12, 2026

    @Nucs
    Member

    Related to #597

  2. Nucs commented on Sep 7, 2026

    @Nucs
    Member

    Fixed by #617 (the byte-identical np.save/np.load port), in 0.70.0 (#628). A shape=() scalar loads correctly now, no off-by-one:

    np.save("scalar.npy", np.array(5.0));
    
    var x = np.load_npy("scalar.npy");
    Console.WriteLine(x.ndim);          // 0
    Console.WriteLine(x.GetDouble(0));  // 5

    Closing.

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