From J Wiki
Jump to navigation Jump to search


This addon has functions for reading and writing numpy npy and npz files.

The npy files should contain a single unnested array. The result of reading an npy file is a J noun.

The npz files are zips of one or more npy files. Data for reading and writing npz files should be a 2 column boxed matrix of names and values.

See the demo.ijs script in the addon.

Numpy docs are at Npy Format .


1. npy files may contain python object arrays, stored as pickles. This is an internal python format that is not well documented for use by external programs. The J addon does not support reading or writing pickles. However, in some cases it should be possible to at least read such data. For example, the object.ijs script in the source was used to read pickles with a mixed matrix of numbers and characters from npy files in the scipy benchmarks suite.

2. So far only boolean, integer and float types are supported for reading. It should be straightforward to add other python datatypes except for objects.


From the demo.ijs script:

   load 'convert/numpy'
   D=. jpath '~temp/'
   wint=. i.3 4
   wbool=. 0 = 3 | wint
   wfloat=. 1.1 * p: i.2 5
   writenpy_pnumpy_ (D,'wbool.npy');wbool
   writenpy_pnumpy_ (D,'wfloat.npy');wfloat
   writenpy_pnumpy_ (D,'wint.npy');wint
   wbool -: readnpy_pnumpy_ D,'wbool.npy'
   wfloat -: readnpy_pnumpy_ D,'wfloat.npy'
   wint -: readnpy_pnumpy_ D,'wint.npy'
   nms=. ;: 'wbool wfloat wint'
   dat=. nms,.".each nms
   writenpz_pnumpy_ (D,'wdata.npz');<dat
   dat -: readnpz_pnumpy_ D,'wdata.npz'

Categories D.5.1.3