Skip to main content

pad variable length sequences with multiples features

Project description

PyPI version pad-sequences Total alerts Language grade: Python deepcode

pad-sequences

Pad variable length sequences with multiples features.

Installation via pip

The pad-sequences git repo is available as PyPi package

pip install "pad-sequences>=0.6.0"

Usage

from pad_sequences import pad_sequences_multi
import tensorflow as tf
# import torch

seq = []
seq.append([[1, 1, 1], [2, 2, 2]])
seq.append([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]])

n_samples = len(seq)
n_features = len(seq[0][0])
n_timesteps = 3

# for input sequences
padded = pad_sequences_multi(seq, padding='pre', value=0,
                             truncating='pre', maxlen=n_timesteps)
# for output sequences
# padded = pad_sequences_multi(seq, padding='post', value=0,
#                              truncating='post', maxlen=n_timesteps)

X = tf.reshape(padded, [n_samples, n_timesteps, n_features])
# X = torch.reshape(torch.tensor(padded), [n_samples, n_timesteps, n_features])

Check the examples folder for notebooks.

Appendix

Install a virtual environment

python3 -m venv .venv
source .venv/bin/activate
pip3 install --upgrade pip
pip3 install -r requirements-dev.txt
pip3 install -r requirements-demo.txt

(If your git repo is stored in a folder with whitespaces, then don’t use the subfolder .venv. Use an absolute path without whitespaces.)

Other python commands

  • Jupyter for the examples: jupyter lab

  • Check syntax: flake8 --ignore=F401 --exclude=$(grep -v '^#' .gitignore | xargs | sed -e 's/ /,/g')

  • Run Unit Tests: pytest

Publish

pandoc README.md --from markdown --to rst -s -o README.rst
python setup.py sdist
twine upload -r pypi dist/*

Clean up

find . -type f -name "*.pyc" | xargs rm
find . -type d -name "__pycache__" | xargs rm -r
rm -r .pytest_cache
rm -r .venv

Debugging

  • Notebooks to profile python code are in the profile folder

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pad-sequences-0.6.1.tar.gz (9.5 kB view details)

Uploaded Source

File details

Details for the file pad-sequences-0.6.1.tar.gz.

File metadata

  • Download URL: pad-sequences-0.6.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.9

File hashes

Hashes for pad-sequences-0.6.1.tar.gz
Algorithm Hash digest
SHA256 36960d61e719d6e3edf62d483566c563b923deb3a0837b403c886ba1e1ef61c3
MD5 f5bfac658558e135466de4434f200576
BLAKE2b-256 b4cfe5a7cfaed432f5bbddfbdb304e0de7c3c6980c98d38ea01df76b48c0f612

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page