0.0.4 • Published 11 months ago

array-sequence-utils v0.0.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 months ago

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)
0.0.4

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago