Skip to content

Latest commit

 

History

History
63 lines (41 loc) · 1.11 KB

sub.md

File metadata and controls

63 lines (41 loc) · 1.11 KB

sub

Subtract one operand from another using NumPy style broadcasting rules.

API

Numeric.math.sub(first, right = 0)

Combines operands with NumPy style broadcast.

  • Parameters:
    • first: First operand as a scalar, vector, or matrix
    • right: Second operand as a scalar, vector, or matrix
  • Returns: Differences matching the broadcast shape of the operands
  • NumPy: Equivalent to np.subtract.

Examples

Subtract two scalars

import Numeric from '@neabyte/numerix'

const difference = Numeric.math.sub(5, 3)

console.log(difference)
// 2

Subtract a scalar from a vector

import Numeric from '@neabyte/numerix'

const differences = Numeric.math.sub([10, 20], 1)

console.log(differences)
// [9,19]

Subtract two vectors element-wise

import Numeric from '@neabyte/numerix'

const differences = Numeric.math.sub([10, 20], [1, 2])

console.log(differences)
// [9,18]

Subtract a vector from a matrix row

import Numeric from '@neabyte/numerix'

const differences = Numeric.math.sub([[10, 20], [30, 40]], [1, 2])

console.log(differences)
// [[9,18],[29,38]]