Published
Edited
Aug 17, 2019
Importers
1 star
Insert cell
Insert cell
Insert cell
function multiply_matrices(A, B) {
let a_rows = A.length;
let a_cols = A[0].length;
let b_rows = B.length;
let b_cols = B[0].length;
if (a_cols != b_rows) return false;
let C = Array2D(a_rows, b_cols, 0);
for (let i=0; i<a_rows; i++) {
for (let k=0; k<b_cols; k++) {
for (let j=0; j<a_cols; j++) {
C[i][k] = C[i][k] + A[i][j]*B[j][k];
}
}
}
return C;
}
Insert cell
sig_cart = signature(cartesian, {
description: `Calculate cartesian product.`,
example: `
const cprod = cartesian([Array], [Array]);
`,

})
Insert cell
// Tests
// signature(myTestedFunc, {
// tests: {
// 'can retrieve data': async (assert) => {
// const data = await myTestedFunc().getData();
// assert(Array.isArray(data), 'data is array');
// assert(data.length, 'data is not empty');
// },
// 'is this finished?': assert => {
// assert(myTestedFunc() !== 'todo: implement', 'actually implemented');
// },
// 'Look, ma! No assert!': () => {
// try { myTestedFunc().notImplemented() }
// catch(e) { throw Error(`Hey signature(), catch this! ${e}`) };
// }
// }})
Insert cell
signature(nxm, {
description: "2D Array with spread operator",
name:"nxm",
example: [`nxm(4,3)`,``],})
Insert cell
nxm = (n, m) => [...Array(n)].map((_,r)=>[...Array(m)].map((d,c)=>c*r))
Insert cell
//https://stackoverflow.com/questions/12303989/cartesian-product-of-multiple-arrays-in-javascript
cartesian = (a, b) => {
let f = (a, b) => [].concat(...a.map(a => b.map(b => [].concat(a, b))));
let cartesian = (a, b, ...c) => b ? cartesian(f(a, b), ...c) : a;
return cartesian(a, b);
}
Insert cell
Array2DSq =(n, val)=> [...Array(n)].map((d,i)=>[...Array(n)].map((d,i)=>val));
Insert cell
Insert cell
Insert cell
md`m_def`
Insert cell
mm_def5
Insert cell
Insert cell
md`## imports `
Insert cell
// import {signature} with {myTheme as signature_theme} from '691ae3b95f02db79@818'
// example
// import {signature_theme} from 691ae3b95f02db79@336
import {signature, viewof RUN_TESTS} from '691ae3b95f02db79@818'
Insert cell
import {signature_theme} from "691ae3b95f02db79"
Insert cell
d3 = require("d3@5")
Insert cell
Insert cell
md`svg matrix multiply`
Insert cell
Insert cell
md` ### signature
- [signature](https://observablehq.com/d/f81da11ab7a92bed)
- [Toolbox](https://observablehq.com/d/691ae3b95f02db79|)
`
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