python Programming Glossary: dtype
Using numpy to build an array of all combinations of two arrays http://stackoverflow.com/questions/1208118/using-numpy-to-build-an-array-of-all-combinations-of-two-arrays 4 6 3 4 7 3 5 6 3 5 7 arrays np.asarray x for x in arrays dtype arrays 0 .dtype n np.prod x.size for x in arrays if out is None.. 3 5 7 arrays np.asarray x for x in arrays dtype arrays 0 .dtype n np.prod x.size for x in arrays if out is None out np.zeros.. for x in arrays if out is None out np.zeros n len arrays dtype dtype m n arrays 0 .size out 0 np.repeat arrays 0 m if arrays..
Why is numpy's einsum faster than numpy's built in functions? http://stackoverflow.com/questions/18365073/why-is-numpys-einsum-faster-than-numpys-built-in-functions built in functions Lets start with three arrays of dtype np.double . Timings are performed on a intel CPU using numpy.. up in microseconds not milliseconds arr_1D np.arange 500 dtype np.double large_arr_1D np.arange 100000 dtype np.double arr_2D.. 500 dtype np.double large_arr_1D np.arange 100000 dtype np.double arr_2D np.arange 500 2 dtype np.double .reshape 500..
Fastest way to list all primes below N in python http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python Returns a array of primes p n assert n 2 sieve np.ones n 2 dtype np.bool for i in xrange 3 int n 0.5 1 2 if sieve i 2 sieve i.. 6 Returns a array of primes 2 p n sieve np.ones n 3 n 6 2 dtype np.bool sieve 0 False for i in xrange int n 0.5 3 1 if sieve..
Simple Python Challenge: Fastest Bitwise XOR on Data Buffers http://stackoverflow.com/questions/2119761/simple-python-challenge-fastest-bitwise-xor-on-data-buffers bitwise_xor byte def slow_xor aa bb a frombuffer aa dtype byte b frombuffer bb dtype byte c bitwise_xor a b r c.tostring.. slow_xor aa bb a frombuffer aa dtype byte b frombuffer bb dtype byte c bitwise_xor a b r c.tostring return r aa urandom 2 20.. SIZE 2 20 def faster_slow_xor aa bb b numpy.fromstring bb dtype numpy.uint64 numpy.bitwise_xor numpy.frombuffer aa dtype numpy.uint64..
Python - Is a dictionary slow to find frequency of each character? http://stackoverflow.com/questions/2522152/python-is-a-dictionary-slow-to-find-frequency-of-each-character ' usr share dict american english' # ucs2 or ucs4 python dtype 2 numpy.uint16 4 numpy.uint32 len buffer u u # count ordinals.. filename encoding 'utf 8' .read a numpy.frombuffer text dtype dtype counts numpy.bincount a # pretty print counts unichr i.. encoding 'utf 8' .read a numpy.frombuffer text dtype dtype counts numpy.bincount a # pretty print counts unichr i v for..
|