本文整理汇总了TypeScript中ndarray.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ndarray.default方法的具体用法?TypeScript ndarray.default怎么用?TypeScript ndarray.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ndarray
的用法示例。
在下文中一共展示了ndarray.default方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: cwise
tape("fill", (t) => {
const fill = cwise({
args: ["index", "array", "scalar"],
body(idx, out, f) {
out = f.apply(undefined, idx);
}
});
const xlen = 10;
const ylen = 5;
const array = ndarray(new Float32Array(xlen * ylen), [xlen, ylen]);
fill(array, (row: number, col: number) => {
return 0;
});
for (let i = 0; i < xlen; i++) {
for (let j = 0; j < ylen; j++) {
t.equals(array.get(i, j), 0, `fill (${i},${j})`);
}
}
fill(array, (row: number, col: number) => {
return 10 * (row + col);
});
for (let i = 0; i < xlen; i++) {
for (let j = 0; j < ylen; j++) {
t.equals(array.get(i, j), 10 * (i + j), `fill (${i},${j})`);
}
}
t.end();
});
示例2: ndarray
import * as ndarray from 'ndarray';
const data = new Int32Array(2 * 2 * 2 + 10);
const a = ndarray(data, [2, 2, 2], [1, 2, 4], 5);
console.log(a.data === data);
console.log(a.shape[0] === 2);
console.log(a.shape[1] === 2);
console.log(a.shape[2] === 2);
console.log(a.stride[0] === 1);
console.log(a.stride[1] === 2);
console.log(a.stride[2] === 4);
console.log(a.offset === 5);
console.log(a.dtype === 'int32');
console.log(a.size === 8);
console.log(a.order[0] === 0);
console.log(a.order[1] === 1);
console.log(a.order[2] === 2);
console.log(a.dimension === 3);
console.log(a.set(0, 0, 0, 1) === 1);
console.log(a.get(0, 0, 0) === 1);
console.log(a.index(1, 1, 1) === 12);
const b = a.lo(0, 0, 0).hi(1, 1, 1);
示例3: ndarray
t.throws(() => { op2block_neg(ndarray([1, 2, 3, 4, 5, 6], [3, 2]), ndarray([1, 2, 3, 4], [2, 2])); });