Skip to content

Instantly share code, notes, and snippets.

@njsmith
njsmith / gist:0651d1d3266bf017c9e2
Last active August 29, 2015 14:07
workaround python 2/3 incompatibilities in formatting/parsing of long integers
import six
import tokenize
import numpy as np
def _filter_tokens(s):
last_token_was_number = False
for token in tokenize.generate_tokens(six.StringIO(s).read):
token_type = token[0]
token_string = token[1]
if (last_token_was_number
>>> np.__version__
'1.8.1'
>>> ar = np.ma.array([1, 1, 1, np.ma.masked, 1, 1, 1])
>>> ar
masked_array(data = [1.0 1.0 1.0 -- 1.0 1.0 1.0],
mask = [False False False True False False False],
fill_value = 1e+20)
>>> np.gradient(ar)
masked_array(data = [0.0 0.0 -- 0.0 -- 0.0 0.0],
@njsmith
njsmith / sequence.py
Created May 15, 2015 07:45
Describing the behavior of CPython `list` etc. in pure Python
# Attempt to implement in pure Python a Sequence class which behaves the same
# way as a CPython object that provides tp_as_sequence but not
# tp_as_number (like, for example, the built-in types list, tuple, ...).
def _proper_subinstance(a, b):
ta = type(a)
tb = type(b)
return ta is not tb and issubclass(ta, tb)
class Sequence(object):
N = 100
x = np.linspace(0, 1, N)
jet_samples_sRGB = jet(x)
jet_samples_Jpapbp = cspace_convert(jet_samples_sRGB, "sRGB1", "CAM02-UCS")
distances = np.cumsum(np.sqrt(np.sum((jet_samples_Jpapbp[:-1, ...] - jet_samples_Jpapbp[1:, ...]) ** 2), axis=-1))
distances = np.concatenate(([0], distances))
newjet_samples_Jpapbp = np.interp(x, distances, jet_samples_Jpapbp)
newjet_samples_sRGB = cspace_convert(newjet_samples_Jpapbp, "CAM02-UCS", "sRGB1")
$ conda create -n anaconda-34 python=3.4 anaconda
<output elided -- I ended up with anaconda 2.3.0 npy19py34_0>
$ source activate anaconda-34
# This is a list of every package they link to outside of what they ship, but see below:
~$ find miniconda/envs/anaconda-34 -name '*.so' | xargs -n1 ldd | grep -v miniconda | cut -f1 -d' ' | sort -u
/lib64/ld-linux-x86-64.so.2
libcrypt.so.1
libc.so.6
@njsmith
njsmith / future-of-numpy-bof.odp
Last active August 29, 2015 14:28
Slides from "Future of NumPy" BoF at SciPy 2015
@njsmith
njsmith / miniNEP1-where.rst
Created July 6, 2011 19:03
miniNEP 1: where= argument for ufuncs

A mini-NEP for the where= argument to ufuncs

To try and make more progress on the whole missing values/masked arrays/... debate, it seems useful to have a more technical discussion of the pieces which we can agree on. This is the first, which attempts to nail down the details of the new where= argument to ufuncs.

Rationale

@njsmith
njsmith / miniNEP2-NA-dtype.rst
Created July 6, 2011 20:35
miniNEP 2: NAs support in dtypes

####################################### miniNEP 2: NA support via special dtypes #######################################

To try and make more progress on the whole missing values/masked arrays/... debate, it seems useful to have a more technical discussion of the pieces which we can agree on. This is the second, which attempts to nail down the details of how NAs can be implemented using special dtype's.

Table of contents

@njsmith
njsmith / ipython-4.0.0 wheel METADATA
Last active November 7, 2015 04:56
METADATA files from some real wheels
Metadata-Version: 2.0
Name: ipython
Version: 4.0.0
Summary: IPython: Productive Interactive Computing
Home-page: http://ipython.org
Author: The IPython Development Team
Author-email: ipython-dev@scipy.org
License: BSD
Download-URL: https://github.com/ipython/ipython/downloads
Keywords: Interactive,Interpreter,Shell,Parallel,Distributed,Web-based computing,Qt console,Embedding
import sys
import os
import os.path
import subprocess
import json
# entry point for 'python -m pip'
def python_m_pip_main():
do_pip(sys.argv)