Skip to content

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

License

Notifications You must be signed in to change notification settings

syarul/sequence_utils

Repository files navigation

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)

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages