{"id":23127414,"url":"https://github.com/aplbrain/npyjs","last_synced_at":"2025-04-06T00:07:23.544Z","repository":{"id":40562146,"uuid":"68390179","full_name":"aplbrain/npyjs","owner":"aplbrain","description":"Read numpy .npy files in JavaScript","archived":false,"fork":false,"pushed_at":"2025-01-13T23:01:03.000Z","size":17024,"stargazers_count":85,"open_issues_count":10,"forks_count":22,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-29T23:07:46.287Z","etag":null,"topics":["3d","javascript","jhuapl","nodejs","npy","npy-files","numpy"],"latest_commit_sha":null,"homepage":"https://aplbrain.github.io/npyjs/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aplbrain.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-16T15:09:20.000Z","updated_at":"2025-03-28T18:25:55.000Z","dependencies_parsed_at":"2022-08-09T23:10:59.029Z","dependency_job_id":"0897c15d-c861-48c2-b8ec-7f4669f9e412","html_url":"https://github.com/aplbrain/npyjs","commit_stats":null,"previous_names":["jhuapl-boss/npyjs"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aplbrain%2Fnpyjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aplbrain%2Fnpyjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aplbrain%2Fnpyjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aplbrain%2Fnpyjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aplbrain","download_url":"https://codeload.github.com/aplbrain/npyjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415967,"owners_count":20935388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d","javascript","jhuapl","nodejs","npy","npy-files","numpy"],"created_at":"2024-12-17T09:06:18.941Z","updated_at":"2025-04-06T00:07:23.505Z","avatar_url":"https://github.com/aplbrain.png","language":"JavaScript","readme":"\u003ch1 align=center\u003enpy.js\u003c/h1\u003e\n\u003ch6 align=center\u003eRead .npy files directly in JS\u003c/h6\u003e\n\n\u003cp align=center\u003e\n    \u003ca href=\"https://www.npmjs.com/package/npyjs\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/npyjs.svg?style=for-the-badge\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/aplbrain/npyjs\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/aplbrain/npyjs.svg?style=for-the-badge\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/aplbrain/npyjs\"\u003e\u003cimg src=\"https://img.shields.io/github/license/aplbrain/npyjs.svg?style=for-the-badge\" /\u003e\u003c/a\u003e\n    \u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/actions/workflow/status/aplbrain/npyjs/test-node.yml?label=Tests\u0026style=for-the-badge\"\u003e\n\u003c/p\u003e\n\nRead .npy files from [numpy](https://numpy.org/doc/1.18/reference/generated/numpy.save.html) in Node/JS.\n\n## Installation\n\nInclude npy.js in your project directly, or:\n\n```shell\nyarn add npyjs\n# npm i npyjs\n```\n\n## Import\n\n```javascript\nimport npyjs from \"npyjs\";\n```\n\n## Usage\n\n-   Create a new npyjs object:\n\n```javascript\nlet n = new npyjs();\n// Or with options:\nlet n = new npyjs({ convertFloat16: false }); // Disable float16 to float32 conversion\n```\n\n-   This object can now be used load .npy files. Arrays can be returned via a JavaScript callback, so usage looks like this:\n\n```javascript\nn.load(\"my-array.npy\", (array, shape) =\u003e {\n    // `array` is a one-dimensional array of the raw data\n    // `shape` is a one-dimensional array that holds a numpy-style shape.\n    console.log(`You loaded an array with ${array.length} elements and ${shape.length} dimensions.`);\n});\n```\n\n-   You can also use this library promise-style using either .then or async await:\n\n```javascript\nn.load(\"test.npy\").then((res) =\u003e {\n    // res has { data, shape, dtype } members.\n});\n```\n\n```javascript\nconst npyArray = await n.load(\"test.npy\");\n```\n\n## Accessing multidimensional array elements\n\n-   You can conveniently access multidimensional array elements using the 'ndarray' library:\n\n```javascript\nimport ndarray from \"ndarray\";\nconst npyArray = ndarray(data, shape);\nnpyArray.get(10, 15);\n```\n\n## Supported Data Types\n\nThe library supports the following NumPy data types:\n\n-   `int8`, `uint8`\n-   `int16`, `uint16`\n-   `int32`, `uint32`\n-   `int64`, `uint64` (as BigInt)\n-   `float32`\n-   `float64`\n-   `float16` (converted to float32 by default)\n\n### Float16 Support\n\nBy default, float16 arrays are automatically converted to float32 for compatibility, since JavaScript doesn't natively support float16. You can control this behavior with the constructor options:\n\n```javascript\n// Default behavior - float16 is converted to float32\nconst n1 = new npyjs();\n// Keep float16 as raw uint16 values without conversion\nconst n2 = new npyjs({ convertFloat16: false });\n```\n\nUnless otherwise specified, all code inside of this repository is covered under the license in [LICENSE](LICENSE).\n\nPlease report bugs or contribute pull-requests on [GitHub](https://github.com/aplbrain/npyjs).\n\n---\n\n\u003cp align=\"center\"\u003e\u003csmall\u003eMade with ♥ at \u003ca href=\"http://www.jhuapl.edu/\"\u003e\u003cimg alt=\"JHU APL\" align=\"center\" src=\"./docs/apl-logo.png\" height=\"23px\"\u003e\u003c/a\u003e\u003c/small\u003e\u003c/p\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faplbrain%2Fnpyjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faplbrain%2Fnpyjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faplbrain%2Fnpyjs/lists"}