|
a |
|
b/code/preprocessing/lib/npy-matlab-master/README.md |
|
|
1 |
[](https://travis-ci.org/kwikteam/npy-matlab) |
|
|
2 |
# npy-matlab |
|
|
3 |
|
|
|
4 |
Code to read and write NumPy's NPY format (`.npy` files) in MATLAB. |
|
|
5 |
|
|
|
6 |
This is experimental code and still work in progress. For example, this code: |
|
|
7 |
- Only reads a subset of all possible NPY files, specifically N-D arrays of |
|
|
8 |
certain data types. |
|
|
9 |
- Only writes little endian, fortran (column-major) ordering |
|
|
10 |
- Only writes with NPY version number 1.0. |
|
|
11 |
- Always outputs a shape according to matlab's convention, e.g. (10, 1) |
|
|
12 |
rather than (10,). |
|
|
13 |
|
|
|
14 |
Feel free to open an issue and/or send a pull request for improving the |
|
|
15 |
state of this project! |
|
|
16 |
|
|
|
17 |
For the complete specification of the NPY format, see the [NumPy documentation](https://www.numpy.org/devdocs/reference/generated/numpy.lib.format.html). |
|
|
18 |
|
|
|
19 |
## Installation |
|
|
20 |
After downloading npy-matlab as a zip file or via git, just add the |
|
|
21 |
npy-matlab directory to your search path: |
|
|
22 |
|
|
|
23 |
```matlab |
|
|
24 |
>> addpath('my-idiosyncratic-path/npy-matlab/npy-matlab') |
|
|
25 |
>> savepath |
|
|
26 |
``` |
|
|
27 |
|
|
|
28 |
## Usage example |
|
|
29 |
```matlab |
|
|
30 |
>> a = rand(5,4,3); |
|
|
31 |
>> writeNPY(a, 'a.npy'); |
|
|
32 |
>> b = readNPY('a.npy'); |
|
|
33 |
>> sum(a(:)==b(:)) |
|
|
34 |
ans = |
|
|
35 |
|
|
|
36 |
60 |
|
|
37 |
``` |
|
|
38 |
|
|
|
39 |
## Tests |
|
|
40 |
Roundtrip testing is performed using Travis CI and GNU Octave, see |
|
|
41 |
the `.travis.yml` file and `tests/test_npy_roundtrip.py`. |
|
|
42 |
|
|
|
43 |
You can also use two "manual testing scripts": |
|
|
44 |
|
|
|
45 |
- See `tests/npy.ipynb` for Python tests. |
|
|
46 |
- See `tests/test_readNPY.m` for MATLAB reading/writing tests. |
|
|
47 |
|
|
|
48 |
## Memory mapping npy files |
|
|
49 |
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. |