Public
Edited
Dec 26, 2022
1 fork
1 star
Insert cell
Insert cell
draw_digit = (n) =>
imshow(
_.chunk(Object.values(mnist_digits[n]).slice(2), 28),
2,
d3.interpolateGreys
)
Insert cell
Insert cell
viewof digit = Inputs.range([0, 9], { value: 0, step: 1 })
Insert cell
digit_displayed = draw_digit(digit)
Insert cell
Insert cell
digits = {
let container = d3.create("div");
d3.range(10).forEach(function (n) {
let div = container.append("div").style("display", "inline-block");
div.append(() => draw_digit(n));
});
return container.node();
}
Insert cell
Insert cell
plot_digit(digit)
Insert cell
plot_digit = (n) =>
Plot.plot({
x: { axis: false },
y: { axis: false },
width: 58,
height: 58,
marks: [
Plot.cell(
Object.values(mnist_digits[n])
.slice(2)
.map((c, i) => ({ x: i % 28, y: Math.floor(i / 28), c })),
{
x: "x",
y: "y",
fill: (o) => d3.interpolateGreys(o.c / 255),
stroke: (o) => d3.interpolateGreys(o.c / 255)
}
)
]
})
Insert cell
// I extracted just one row for each of the 10 digits from Kaggle's training data set
mnist_digits = FileAttachment("mnist_digits.csv").csv({ typed: true })
Insert cell
import { imshow } from "@sw1227/reusable-2d-array-image-function"
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