Git Product home page Git Product logo

npy-matlab's Introduction

Travis

npy-matlab

Code to read and write NumPy's NPY format (.npy files) in MATLAB.

This is experimental code and still work in progress. For example, this code:

  • Only reads a subset of all possible NPY files, specifically N-D arrays of certain data types.
  • Only writes little endian, fortran (column-major) ordering
  • Only writes with NPY version number 1.0.
  • Always outputs a shape according to matlab's convention, e.g. (10, 1) rather than (10,).

Feel free to open an issue and/or send a pull request for improving the state of this project!

For the complete specification of the NPY format, see the NumPy documentation.

Installation

After downloading npy-matlab as a zip file or via git, just add the npy-matlab directory to your search path:

>> addpath('my-idiosyncratic-path/npy-matlab/npy-matlab')  
>> savepath

Usage example

>> a = rand(5,4,3);
>> writeNPY(a, 'a.npy');
>> b = readNPY('a.npy');
>> sum(a(:)==b(:))
ans =

    60

Tests

Roundtrip testing is performed using Travis CI and GNU Octave, see the .travis.yml file and tests/test_npy_roundtrip.py.

You can also use two "manual testing scripts":

  • See tests/npy.ipynb for Python tests.
  • See tests/test_readNPY.m for MATLAB reading/writing tests.

Memory mapping npy files

See examples/exampleMemmap.m for an example of how to memory map a .npy file in MATLAB, which is not trivial when the file uses C-ordering (i.e., row-major order) rather than Fortran-ordering (i.e., column-major ordering). MATLAB's memory mapping only supports Fortran-ordering, but Python's default is C-ordering so .npy files created with Python defaults are not straightforward to read in MATLAB.

npy-matlab's People

Contributors

nsteinme avatar sappelhoff avatar rossant avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.