¡@

Home 

python Programming Glossary: np

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

function takes float values given a 6 dim numpy array as input. What I tried to do initially was this 1 First I created a.. a m And then I evaluate my function like this values combs np.arange 0 1 0.1 6 for val in values print F val This works but.. It's ca. 5 faster than using itertools. import numpy as np def cartesian arrays out None Generate a cartesian product..

“Large data” work flows using pandas

http://stackoverflow.com/questions/14262433/large-data-work-flows-using-pandas

then what do you do Is step 2 ad hoc or repeatable Input flat files how many rough total size in Gb. How are these.. anyhow The following is pseudocode. import numpy as np import pandas as pd # create a store store pd.HDFStore 'mystore.h5'..

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

the set. Nevertheless it works at least for me for some input numbers sum get_primes 2000000 142913828922L #That's the correct.. psyco.full from math import sqrt ceil import numpy as np def rwh_primes n # http stackoverflow.com questions 2068372.. way to list all primes below n in python 3035188#3035188 Input n 6 Returns a list of primes 2 p n correction n 6 1 n 0 n..

Generate a heatmap in MatPlotLib using a scatter data set

http://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set

you can use numpy's histogram2d function import numpy as np import numpy.random import matplotlib.pyplot as plt # Generate.. matplotlib.pyplot as plt # Generate some test data x np.random.randn 8873 y np.random.randn 8873 heatmap xedges yedges.. as plt # Generate some test data x np.random.randn 8873 y np.random.randn 8873 heatmap xedges yedges np.histogram2d x y bins..

Inverse Distance Weighted (IDW) Interpolation with Python

http://stackoverflow.com/questions/3104781/inverse-distance-weighted-idw-interpolation-with-python

local from __future__ import division import numpy as np from scipy.spatial import cKDTree as KDTree # http docs.scipy.org.. None # nnear nearest neighbours of each query point q np.asarray q qdim q.ndim if qdim 1 q np.array q if self.wsum is.. of each query point q np.asarray q qdim q.ndim if qdim 1 q np.array q if self.wsum is None self.wsum np.zeros nnear self.distances..

Peak detection in a 2D array

http://stackoverflow.com/questions/3684484/peak-detection-in-a-2d-array

keep it 'simple'. Here's a version that can be loaded with np.loadtxt Results So I tried @jextee's solution see the results.. it worked as well . Here is how you do it import numpy as np from scipy.ndimage.filters import maximum_filter from scipy.ndimage.morphology.. had to reshape. Numpy ignored the shape header. paws_data np.loadtxt paws.txt .reshape 4 11 14 #getting a list of images..

How can I improve my paw detection?

http://stackoverflow.com/questions/4087919/how-can-i-improve-my-paw-detection

coded_paws return object_slices Blur the input data a bit to make sure the paws have a continuous footprint... explanations . The vast majority of this is reading the input and making an animation. The actual paw detection is only.. paw detection is only 5 lines of code. import numpy as np import scipy as sp import scipy.ndimage import matplotlib.pyplot..

matplotlib Update a Plot

http://stackoverflow.com/questions/4098131/matplotlib-update-a-plot

option import matplotlib.pyplot as plt import numpy as np x np.linspace 0 6 np.pi 100 y np.sin x # You probably won't.. import matplotlib.pyplot as plt import numpy as np x np.linspace 0 6 np.pi 100 y np.sin x # You probably won't need.. as plt import numpy as np x np.linspace 0 6 np.pi 100 y np.sin x # You probably won't need this if you're embedding..

Using strides for an efficient moving average filter

http://stackoverflow.com/questions/4936620/using-strides-for-an-efficient-moving-average-filter

etc At any rate here's how you do it import numpy as np def rolling_window_lastaxis a window Directly taken from Erik.. 1 window 1 window strides a.strides a.strides 1 return np.lib.stride_tricks.as_strided a shape shape strides strides def.. a win a a.swapaxes 2 i return a filtsize 3 3 a np.zeros 10 10 dtype np.float a 5 7 5 1 b rolling_window a filtsize..

Matplotlib: How to put individual tags for a scatter plot

http://stackoverflow.com/questions/5147112/matplotlib-how-to-put-individual-tags-for-a-scatter-plot

this question Perhaps use plt.annotate import numpy as np import matplotlib.pyplot as plt N 10 data np.random.random N.. numpy as np import matplotlib.pyplot as plt N 10 data np.random.random N 4 labels 'point 0 '.format i for i in range..

Iterating over every two elements in a list

http://stackoverflow.com/questions/5389507/iterating-over-every-two-elements-in-a-list

Is shared readonly data copied to different processes for Python multiprocessing?

http://stackoverflow.com/questions/5549190/is-shared-readonly-data-copied-to-different-processes-for-python-multiprocessing

import multiprocessing import ctypes import numpy as np shared_array_base multiprocessing.Array ctypes.c_double 10 10.. multiprocessing.Array ctypes.c_double 10 10 shared_array np.ctypeslib.as_array shared_array_base.get_obj shared_array shared_array.reshape..

Python/Matplotlib - Is there a way to make a discontinuous axis?

http://stackoverflow.com/questions/5656798/python-matplotlib-is-there-a-way-to-make-a-discontinuous-axis

like this import matplotlib.pylab as plt import numpy as np # If you're not familiar with np.r_ don't worry too much about.. as plt import numpy as np # If you're not familiar with np.r_ don't worry too much about this. It's just # a series with.. 0 to 1 spaced at 0.1 and 9 to 10 with the same spacing. x np.r_ 0 1 0.1 9 10 0.1 y np.sin x fig ax ax2 plt.subplots 1 2 sharey..

Use numpy array in shared memory for multiprocessing

http://stackoverflow.com/questions/7894791/use-numpy-array-in-shared-memory-for-multiprocessing

array with shared_arr.get_lock # synchronize access arr np.frombuffer shared_arr.get_obj # no data copying arr i arr i.. as mp from contextlib import closing import numpy as np info mp.get_logger .info def main logger mp.log_to_stderr logger.setLevel.. arr tonumpyarray shared_arr # fill with random values arr np.random.uniform size N arr_orig arr.copy # write to arr from..

Python out of memory on large CSV file (numpy)

http://stackoverflow.com/questions/8956832/python-out-of-memory-on-large-csv-file-numpy

Versions 2.6 lib python2.6 site packages numpy lib npyio.py line 1495 in genfromtxt for i line in enumerate itertools.chain.. numpy.fromiter . If you have enough ram consider using np.loadtxt 'yourfile.txt' delimiter ' ' You may also need to specify.. regular you can improve on them greatly. import numpy as np def generate_text_file length 1e6 ncols 20 data np.random.random..

Simple Digit Recognition OCR in OpenCV-Python

http://stackoverflow.com/questions/9413216/simple-digit-recognition-ocr-in-opencv-python

model of letter_recog.py just for testing import numpy as np import cv2 fn 'letter recognition.data' a np.loadtxt fn np.float32.. numpy as np import cv2 fn 'letter recognition.data' a np.loadtxt fn np.float32 delimiter ' ' converters 0 lambda ch ord.. np import cv2 fn 'letter recognition.data' a np.loadtxt fn np.float32 delimiter ' ' converters 0 lambda ch ord ch ord 'A'..

Numpy: Should I use newaxis or None?

http://stackoverflow.com/questions/944863/numpy-should-i-use-newaxis-or-none

to create an axis of length one e.g. import numpy as np print np.zeros 3 5 np.newaxis .shape # shape will be 3 1 5 The.. create an axis of length one e.g. import numpy as np print np.zeros 3 5 np.newaxis .shape # shape will be 3 1 5 The documentation.. of length one e.g. import numpy as np print np.zeros 3 5 np.newaxis .shape # shape will be 3 1 5 The documentation states..

numpy array creating with a sequence

http://stackoverflow.com/questions/10753528/numpy-array-creating-with-a-sequence

for your example the NumPy equivalent is import numpy as NP v NP.r_ .2 1 10 60.8 print v 0.2 1. 2. 3. 4. 5. 6. 7. 8. 9... your example the NumPy equivalent is import numpy as NP v NP.r_ .2 1 10 60.8 print v 0.2 1. 2. 3. 4. 5. 6. 7. 8. 9. 60.8.. 3. 4. 5. 6. 7. 8. 9. 60.8 The column wise counterpart is NP.c_ .2 1 10 60.8 slice notation works as expected start stop..

How to make a checkerboard in numpy?

http://stackoverflow.com/questions/2169478/how-to-make-a-checkerboard-in-numpy

numpy share improve this question import numpy as NP def checkerboard w h re NP.r_ w 0 1 ro NP.r_ w 1 0 return NP.row_stack.. this question import numpy as NP def checkerboard w h re NP.r_ w 0 1 ro NP.r_ w 1 0 return NP.row_stack h re ro AB checkerboard.. import numpy as NP def checkerboard w h re NP.r_ w 0 1 ro NP.r_ w 1 0 return NP.row_stack h re ro AB checkerboard 5 10 ..

Algorithm to find which number in a list sum up to a certain number

http://stackoverflow.com/questions/3420937/algorithm-to-find-which-number-in-a-list-sum-up-to-a-certain-number

on the constraints in the general case this problem is NP Complete. However if the maximum search sum let's call it S..

Extracting nouns from Noun Phase in NLP

http://stackoverflow.com/questions/5143788/extracting-nouns-from-noun-phase-in-nlp

sent for tree in trees print tree tokens find_all_NP tree tokens1 nltk.word_tokenize tokens 0 print tokens1 and obtained.. and obtained the following output S VP V Give Det me NP Det the N review PP P of N movie S VP V Give Det me NP Det the.. me NP Det the N review PP P of N movie S VP V Give Det me NP Det the N review NP PP P of N movie 'the' 'review' 'of' 'movie'..

Subset sum Problem

http://stackoverflow.com/questions/6012963/subset-sum-problem

. But as someone pointed out this problem is indeed NP Complete. Meaning every known exact algorithm has an exponential..

English grammar for parsing in NLTK

http://stackoverflow.com/questions/6115677/english-grammar-for-parsing-in-nltk

be massively decreased SBARQ WHADVP WRB how SQ MD can NP NP DT the JJ net NN amount PP IN of NP NP NNS entropy PP IN.. be massively decreased SBARQ WHADVP WRB how SQ MD can NP NP DT the JJ net NN amount PP IN of NP NP NNS entropy PP IN of.. WRB how SQ MD can NP NP DT the JJ net NN amount PP IN of NP NP NNS entropy PP IN of NP DT the NN universe VP VB be ADJP..

whats the fastest way to find eigenvalues/vectors in python?

http://stackoverflow.com/questions/6684238/whats-the-fastest-way-to-find-eigenvalues-vectors-in-python

from this library eig eigvalsh and eigh . import numpy as NP from scipy import linalg as LA A NP.random.randint 0 10 25 .reshape.. eigh . import numpy as NP from scipy import linalg as LA A NP.random.randint 0 10 25 .reshape 5 5 A array 9 5 4 3 7 3 3 2..

Python machine-learning library?

http://stackoverflow.com/questions/7326958/python-machine-learning-library

and the relevant scikits.learn module import numpy as NP from sklearn import neighbors as kNN # load one of the sklearn..

Finding an optimal solution that minimizes a constraint?

http://stackoverflow.com/questions/7927787/finding-an-optimal-solution-that-minimizes-a-constraint

cover problem as mhum suggests . The set cover problem is NP hard and hard to approximate but in practice branch and bound..

NoSQL Solution for Persisting Graphs at Scale

http://stackoverflow.com/questions/9302295/nosql-solution-for-persisting-graphs-at-scale

log file tailing on your shell window import numpy as NP import networkx as NX # start a redis client connect to the.. built in function reduced to code these two steps are AM NP.array map int r1.hgetall node .values for node in r1.keys #..