Public
Edited
Dec 15, 2023
Insert cell
Insert cell
h5wasm = {
const lib = await import("https://cdn.jsdelivr.net/npm/h5wasm@0.7.0/dist/esm/hdf5_hl.js");
await lib.ready;
return lib;
}
Insert cell
f = new h5wasm.File("array.h5", "w");
Insert cell
// Data is written to HDF5 files in C-order (row-major)
data = [
[11, 12, 13, 14],
[21, 22, 23, 24],
[31, 32, 33, 34]
];
Insert cell
// But when writing it to disk, we flatten it first:
flat_data = data.flat();
Insert cell
dset = f.create_dataset({name: "dataset", data: flat_data, shape: [3,4]}); // 3 rows, 4 columns
Insert cell
// Verify that the stored data comes back in the shape you expect:
dset.to_array();
Insert cell
Insert cell
// get the first row, and all of the columns (empty slice selection means all)
dset.slice([[0,1], []]);
Insert cell
// null for the start value of a slice is equivalent to zero (or None in a numpy slice): from the start
// null for the second value is equivalent to the dimension size N, which means all elements to the end
dset.slice([[0,1], [2, null]]);
Insert cell
// the optional third element of the slice is 'stride', so you can take e.g. every other column like this:
dset.slice([[0,1], [null, null, 2]]);
Insert cell
// get the second and third columns:
dset.slice([[], [1,3]]);
Insert cell
// get the columns in column-order by adjusting the stride:
dset.slice([[], [
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