function times
times(
x: number,
y: number,
): number

Element-wise multiplication of arrays, matrices, or numbers.

Performs element-by-element multiplication. X and Y must have the same dimensions unless one is a number.

Examples

Multiply two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(5, 6), 30);

Element-wise multiplication of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], [3, -1, 0]), [15, -6, 0]);

Multiply a number with each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], 10), [50, 60, 40]);

Element-wise multiplication of two matrices

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[10, 18], [3, 8]]);

Multiply a number with each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(2, [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);

Parameters

x: number

The first operand

y: number

The second operand

Return Type

number

The result of element-wise multiplication

Throws

If no arguments are provided or if the input dimensions do not match

times(
x: number,
y: array,
): array

Element-wise multiplication of arrays, matrices, or numbers.

Performs element-by-element multiplication. X and Y must have the same dimensions unless one is a number.

Examples

Multiply two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(5, 6), 30);

Element-wise multiplication of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], [3, -1, 0]), [15, -6, 0]);

Multiply a number with each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], 10), [50, 60, 40]);

Element-wise multiplication of two matrices

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[10, 18], [3, 8]]);

Multiply a number with each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(2, [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);

Parameters

x: number

The first operand

The second operand

Return Type

The result of element-wise multiplication

Throws

If no arguments are provided or if the input dimensions do not match

times(
x: array,
y: number,
): array

Element-wise multiplication of arrays, matrices, or numbers.

Performs element-by-element multiplication. X and Y must have the same dimensions unless one is a number.

Examples

Multiply two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(5, 6), 30);

Element-wise multiplication of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], [3, -1, 0]), [15, -6, 0]);

Multiply a number with each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], 10), [50, 60, 40]);

Element-wise multiplication of two matrices

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[10, 18], [3, 8]]);

Multiply a number with each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(2, [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);

Parameters

The first operand

y: number

The second operand

Return Type

The result of element-wise multiplication

Throws

If no arguments are provided or if the input dimensions do not match

times(
x: array,
y: array,
): array

Element-wise multiplication of arrays, matrices, or numbers.

Performs element-by-element multiplication. X and Y must have the same dimensions unless one is a number.

Examples

Multiply two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(5, 6), 30);

Element-wise multiplication of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], [3, -1, 0]), [15, -6, 0]);

Multiply a number with each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], 10), [50, 60, 40]);

Element-wise multiplication of two matrices

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[10, 18], [3, 8]]);

Multiply a number with each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(2, [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);

Parameters

The first operand

The second operand

Return Type

The result of element-wise multiplication

Throws

If no arguments are provided or if the input dimensions do not match

times(
x: number,
y: matrix,
): matrix

Element-wise multiplication of arrays, matrices, or numbers.

Performs element-by-element multiplication. X and Y must have the same dimensions unless one is a number.

Examples

Multiply two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(5, 6), 30);

Element-wise multiplication of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], [3, -1, 0]), [15, -6, 0]);

Multiply a number with each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], 10), [50, 60, 40]);

Element-wise multiplication of two matrices

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[10, 18], [3, 8]]);

Multiply a number with each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(2, [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);

Parameters

x: number

The first operand

The second operand

Return Type

The result of element-wise multiplication

Throws

If no arguments are provided or if the input dimensions do not match

times(
x: matrix,
y: number,
): matrix

Element-wise multiplication of arrays, matrices, or numbers.

Performs element-by-element multiplication. X and Y must have the same dimensions unless one is a number.

Examples

Multiply two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(5, 6), 30);

Element-wise multiplication of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], [3, -1, 0]), [15, -6, 0]);

Multiply a number with each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], 10), [50, 60, 40]);

Element-wise multiplication of two matrices

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[10, 18], [3, 8]]);

Multiply a number with each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(2, [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);

Parameters

The first operand

y: number

The second operand

Return Type

The result of element-wise multiplication

Throws

If no arguments are provided or if the input dimensions do not match

times(
x: matrix,
y: matrix,
): matrix

Element-wise multiplication of arrays, matrices, or numbers.

Performs element-by-element multiplication. X and Y must have the same dimensions unless one is a number.

Examples

Multiply two numbers

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(5, 6), 30);

Element-wise multiplication of two vectors

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], [3, -1, 0]), [15, -6, 0]);

Multiply a number with each element of an array

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([5, 6, 4], 10), [50, 60, 40]);

Element-wise multiplication of two matrices

import { assertEquals } from "jsr:@std/assert";

assertEquals(times([[5, 6], [3, 4]], [[2, 3], [1, 2]]), [[10, 18], [3, 8]]);

Multiply a number with each element of a matrix

import { assertEquals } from "jsr:@std/assert";

assertEquals(times(2, [[1, 2], [3, 4]]), [[2, 4], [6, 8]]);

Parameters

The first operand

The second operand

Return Type

The result of element-wise multiplication

Throws

If no arguments are provided or if the input dimensions do not match

Usage

import times from "elemop/times.ts";