Public
Edited
Feb 19, 2020
Importers
3 stars
Hello, A5Hello, PGLiteINSEE ParquetHello, apcachDruidJS workerHello, OrbitWord Tour: 40k words and their friendsHello, spectral.jsHello, petite-vueHello, @thi.ng/grid-iteratorsHello, thumbhashHello, SwissGLHello, QOI (and glitches)Hello, orbHello, cosmographHello, TabulatorUsing d3.blur with PlotMath.cbrtHello debounceColorcetHello, gliiHello, Open MeteoHello, PyWaveletsHello, typesenseHello, libgifHello, kmeans-engineHappy anniversary, Project Gutenberg!Hello, fflateHello, ArchieML!Hello, d3-bboxCollideHello, jsgeoda!Hello, EDTF!Hello, protovis!Hello, placekeyHello, fuse.jsHello, Reorder.jsHello, shadow DOMjszipHello, procedural-glHello, qhullHello, genetic-jsDruidJSHello, Tippy.jsHello, paintWorkletBig πHello, AutoencoderHello, Shakespearean UUIDsHello, ccwt.jsHello, constrainautorHello, talismanHello, polygon-offsetHello p-queueHello async-poolHello rollup-plugin-asciiHello, algebra.jsHello, pixi.jsHello, d3-renderHello zip/unzipCumulative Wikipedia DonationsHTML <details>regl texture
Hello, npyjs
Hello protobufHello, pencil touchHello, LOESSHello html2canvaslegra mapscolor2cssHello, ecsy2D point distributionsHello, delatinThe gpu.js loopDijkstra’s shortest-path treeHello nojacko/Dijkstras-jsHello, tcort/dijkstrajsHello, lambdabaa/dijkstraHello, gpu.js v2Hello jsqrHello qrcodeHello SharedArrayBufferHello GamePad APIHello vtk.jsHello nd4jsHello BiofabricTravelling with a self-organizing mapHello glitchHello UMAP-jsHello pandemoniumHello iocaneHello JSON-editorHello d3-griddingHello mljs/knnWorkerHello lalolibImage to GPU.jsImage to blink.jsTissot's indicatrixVega projectionsHello WebCLGLUsing d3-inertia with observableVideo contouring 3ngraph: pagerank, louvain…Union-FindPerceptron (simple statistics)mljsHello h3-jsEmoji FlagsHello, poisson-disk-sampling
Insert cell
Insert cell
Insert cell
// adapted from https://github.com/jhuapl-boss/npyjs
class npyjs {
constructor(opts) {
if (opts) {
throw [
"No arguments accepted to npyjs constructor.",
"For usage, go to https://github.com/jhuapl-boss/npyjs."
].join(" ");
}

this.dtypes = {
"<u1": {
name: "uint8",
size: 8,
arrayConstructor: Uint8Array
},
"|u1": {
name: "uint8",
size: 8,
arrayConstructor: Uint8Array
},
"|i1": {
name: "int8",
size: 8,
arrayConstructor: Int8Array
},
"<u4": {
name: "uint32",
size: 32,
arrayConstructor: Int32Array
},
"<i4": {
name: "int32",
size: 32,
arrayConstructor: Int32Array
},
"<u8": {
name: "uint64",
size: 64,
arrayConstructor: BigUint64Array
},
"<i8": {
name: "int64",
size: 64,
arrayConstructor: BigInt64Array
},
"<f4": {
name: "float32",
size: 32,
arrayConstructor: Float32Array
},
"<f8": {
name: "float64",
size: 64,
arrayConstructor: Float64Array
}
};
}

parse(arrayBufferContents) {
// const version = arrayBufferContents.slice(6, 8); // Uint8-encoded
const headerLength = new DataView(
arrayBufferContents.slice(8, 10)
).getUint8(0);
const offsetBytes = 10 + headerLength;

const hcontents = new TextDecoder("utf-8").decode(
new Uint8Array(arrayBufferContents.slice(10, 10 + headerLength))
);
const header = JSON.parse(
hcontents
.replace(/'/g, '"')
.replace("False", "false")
.replace("(", "[")
.replace(/,*\),*/g, "]")
);
const shape = header.shape;

const dtype = this.dtypes[header.descr];

const nums = new dtype["arrayConstructor"](
arrayBufferContents,
offsetBytes
);

return {
dtype: dtype.name,
data: nums,
shape
};
}
}
Insert cell
Insert cell
Insert cell
FileAttachment("10-float32.npy")
.arrayBuffer()
.then(d => new npyjs().parse(d))
Insert cell
Insert cell
import { file } from "@jashkenas/inputs"
Insert cell
viewof f = file()
Insert cell
f.arrayBuffer().then(d => new npyjs().parse(d))
Insert cell
Insert cell
fetch(
"https://rawcdn.githack.com/aplbrain/npyjs/ba60a3a529f3210dd07d2ed05ab628939e18b6a7/test/data/4x4x4x4x4-float32.npy"
)
.then(d => d.arrayBuffer())
.then(d => new npyjs().parse(d))
Insert cell
// aplbrain/npyjs is licensed under the Apache License 2.0
LICENSE = "apache-2.0"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more