當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ndarray類代碼示例

本文整理匯總了TypeScript中ndarray的典型用法代碼示例。如果您正苦於以下問題:TypeScript ndarray類的具體用法?TypeScript ndarray怎麽用?TypeScript ndarray使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ndarray類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: tape

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();
});
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:34,代碼來源:cwise-tests.ts

示例2: Int32Array

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);
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:24,代碼來源:ndarray-tests.ts

示例3: op2block_neg

	t.throws(() => { op2block_neg(ndarray([1, 2, 3, 4, 5, 6], [3, 2]), ndarray([1, 2, 3, 4], [2, 2])); });
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:1,代碼來源:cwise-tests.ts

示例4: op2block_pos

	t.throws(() => { op2block_pos(ndarray([1, 2, 3], [3]), ndarray([1, 2, 3, 4, 5, 6], [3, 2])); });
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:1,代碼來源:cwise-tests.ts

示例5: op3

	t.throws(() => { op3(ndarray([1, 2], [2]), ndarray([1, 2, 3], [3]), ndarray([1, 2, 3], [3])); });
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:1,代碼來源:cwise-tests.ts

示例6: op2

	t.throws(() => { op2(ndarray([1, 2, 3, 4, 5, 6], [3, 2]), ndarray([1, 2, 3], [3, 1])); });
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:1,代碼來源:cwise-tests.ts


注:本文中的ndarray類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。