array-sequence-utils

0.0.4 • Public • Published

sequence_utils

A simple utility to pad and truncate arrays to the same length

NPM Version sequence_utils CI

converted tensorflow.keras.preprocessing.sequence

Usage

    npm install array-sequence-utils
import { pad_sequences } from 'array-sequence-utils'

const sequences = [[10, 20, 30], [5, 15], [], [1, 2, 3, 4, 5, 6]]

console.log(pad_sequences(sequences, 4, 'post', 'post'))
// [[10, 20, 30, 0], [5, 15, 0, 0], [0, 0, 0, 0], [1, 2, 3, 4]]

Params

  • @param {number[][]} vectors The sequences represented as an array of array of numbers.
  • @param {number} maxLen Maximum length. Sequences longer than maxLen will be truncated. Sequences shorter than maxLen will be padded.
  • @param {'pre'|'post'} padding Padding type, default to 'pre'.
  • @param {'pre'|'post'} truncating Truncation type, default to 'pre'.
  • @param {number} value Padding value, default to 0 (which usually reserve for padding)

Package Sidebar

Install

npm i array-sequence-utils

Weekly Downloads

0

Version

0.0.4

License

Apache-2.0

Unpacked Size

18.3 kB

Total Files

6

Last publish

Collaborators

  • syarul