{"library":"numpy-parser","title":"NumPy .npy File Parser","description":"numpy-parser is a JavaScript library specifically designed for parsing binary `.npy` files, the standard format for storing NumPy arrays. It supports various TypedArray subclasses including `float32`, `float64`, `int8`, `int16`, `int32`, `uint8`, `uint16`, and `uint32`. The current stable version is 1.2.3; however, the package was last published in January 2019, indicating it is in maintenance mode rather than active development. Its primary utility lies in enabling direct data exchange with Python's scientific computing ecosystem by allowing JavaScript applications to read these highly optimized binary array files. The README mentions future work for 16-bit float support, but this remains an unimplemented feature.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install numpy-parser"],"cli":null},"imports":["import { fromArrayBuffer } from 'numpy-parser';","import { fromArrayBuffer } from 'numpy-parser';","import type { NpyArray } from 'numpy-parser';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { fromArrayBuffer } from 'numpy-parser';\n\ninterface NpyArray {\n  data: TypedArray; // e.g., Float32Array, Int32Array\n  dtype: string;\n  shape: number[];\n  fortranOrder: boolean;\n}\n\n// This example demonstrates parsing an ArrayBuffer obtained from a .npy file.\n// You would typically load this buffer from a file system (Node.js) or network (browser).\n\n// --- Node.js Example (requires a 'data.npy' file) ---\n// import { readFileSync } from 'node:fs';\n// try {\n//   const filePath = './data.npy'; // Path to your .npy file\n//   const fileBuffer = readFileSync(filePath);\n//   const arrayBufferNode = fileBuffer.buffer; // Get the underlying ArrayBuffer\n//   const parsedDataNode = fromArrayBuffer(arrayBufferNode) as NpyArray;\n//   console.log('Node.js Parsed Data:', parsedDataNode.data.slice(0, 5));\n//   console.log('Node.js Data Type:', parsedDataNode.dtype);\n//   console.log('Node.js Shape:', parsedDataNode.shape);\n// } catch (error) {\n//   console.error('Error reading/parsing .npy in Node.js:', error);\n// }\n\n// --- Browser Example (requires an accessible .npy URL) ---\nasync function loadAndParseNpy(url: string) {\n  try {\n    console.log(`Fetching .npy file from: ${url}`);\n    const response = await fetch(url);\n    if (!response.ok) {\n      throw new Error(`HTTP error! Status: ${response.status}`);\n    }\n    const arrayBuffer = await response.arrayBuffer();\n    \n    const parsedData = fromArrayBuffer(arrayBuffer) as NpyArray;\n    \n    console.log('Successfully parsed .npy file:');\n    console.log('Data Type:', parsedData.dtype); // e.g., 'float32', 'int8'\n    console.log('Shape:', parsedData.shape);     // e.g., [100, 200]\n    console.log('First 10 data elements:', parsedData.data.slice(0, 10));\n    return parsedData;\n  } catch (error) {\n    console.error('Failed to load or parse .npy file:', error);\n    return null;\n  }\n}\n\n// Replace with a URL to an actual .npy file for a live example.\n// For instance, you could serve a small .npy file locally or use a public one if available.\n// Example using a placeholder URL:\nloadAndParseNpy('https://example.com/path/to/your/data.npy');\n\n// To run this in a real browser, create an HTML file:\n/*\n<script type=\"module\">\n  import { fromArrayBuffer } from 'https://cdn.jsdelivr.net/npm/numpy-parser@1.2.3/dist/index.mjs';\n  // ... rest of the loadAndParseNpy function ...\n  loadAndParseNpy('https://example.com/path/to/your/data.npy');\n</script>\n*/","lang":"typescript","description":"Demonstrates how to parse an ArrayBuffer using `fromArrayBuffer`, with examples for obtaining the buffer in both Node.js and browser environments.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}