Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 1.15 KB

pad.md

File metadata and controls

65 lines (43 loc) · 1.15 KB

pad

Add entries around an array using the chosen padding mode.

API

Numeric.shape.pad(input, width, method = 'constant', value = 0)

Adds entries around the array using the chosen mode.

  • Parameters:
    • input: Array to pad
    • width: Number of entries added on each side
    • method: Padding method applied to the array
    • value: Constant value used by constant padding
  • Returns: Padded array with the added entries
  • NumPy: Equivalent to np.pad.

Examples

Pad both sides with zeros

import Numeric from '@neabyte/numerix'

const values = Numeric.shape.pad([1, 2], 1)

console.log(values)
// [0,1,2,0]

Pad with different side widths

import Numeric from '@neabyte/numerix'

const values = Numeric.shape.pad([1, 2], [1, 2])

console.log(values)
// [0,1,2,0,0]

Pad by repeating the edge values

import Numeric from '@neabyte/numerix'

const values = Numeric.shape.pad([1, 2], 1, 'edge')

console.log(values)
// [1,1,2,2]

Pad with a custom fill value

import Numeric from '@neabyte/numerix'

const values = Numeric.shape.pad([1, 2], 1, 'constant', 9)

console.log(values)
// [9,1,2,9]