Skip to content

Instantly share code, notes, and snippets.

@jcmgray
jcmgray / batch_contract.py
Last active May 12, 2024 07:58
Batched tensor contraction - essentially batched tensordot, but using einsum notation.
from numpy import tensordot, stack
def einsum_to_axes(lhix, rhix):
"""Take two einsum inputs (strs) and produce
the tuples of ints required for tensordot.
"""
ix_rm = set(lhix) & set(rhix)
lh_ax, rh_ax = [], []
for ix in ix_rm:
@jcmgray
jcmgray / get_outdated_pkgs_not_managed_by_conda.py
Last active July 17, 2018 14:57
Find the set of python packages, not managed by conda, which are out of date according to pip
#!/usr/bin/env python
import subprocess
# find the names of packages conda says are managed by pip
conda_raw = subprocess.run(['conda', 'list'], stdout=subprocess.PIPE).stdout.decode('utf-8')
pip_only_pkgs = {ln.split(' ')[0] for ln in conda_raw.split('\n') if '<pip>' in ln}
# find the names of packages pip says are outdated (assumes column pip output)
pip_raw = subprocess.run(['pip', 'list', '--outdated'], stdout=subprocess.PIPE).stdout.decode('utf-8')