Questions tagged [numpy]
NumPy is one of the many modules in Python that adds support of large multidimensional arrays and matrixes, along with a large library of high-level mathematical functions for operations with these arrays.
numpy
114,582
questions
33
votes
29
answers
46k
views
How to make a checkerboard in numpy?
I'm using numpy to initialize a pixel array to a gray checkerboard (the classic representation for "no pixels", or transparent). It seems like there ought to be a whizzy way to do it with ...
1
vote
3
answers
530
views
Python: strange numbers being pulled from binary file /confusion with hex and decimals
This might be extremely trivial, and if so I apologise, but I'm getting really confused with the outputs I'm getting: hex? decimal? what?
Here's an example, and what it returns:
>>> print '...
4
votes
3
answers
5k
views
Looking for the fastest way to find the exact overlap between two arrays of equal length in numpy
I am looking for the optimal (fastest) way to find the exact overlap between two arrays in numpy. Given two arrays x and y
x = array([1,0,3,0,5,0,7,4],dtype=int)
y = array([1,4,0,0,5,0,6,4],dtype=int)...
16
votes
4
answers
32k
views
What is the equivalent of 'fread' from Matlab in Python?
I have practically no knowledge of Matlab, and need to translate some parsing routines into Python. They are for large files, that are themselves divided into 'blocks', and I'm having difficulty right ...
13
votes
2
answers
34k
views
assigning points to bins
What is a good way to bin numerical values into a certain range? For example, suppose I have a list of values and I want to bin them into N bins by their range. Right now, I do something like this:
...
12
votes
5
answers
6k
views
Python: Analysis on CSV files 100,000 lines x 40 columns
I have about a 100 csv files each 100,000 x 40 rows columns. I'd like to do some statistical analysis on it, pull out some sample data, plot general trends, do variance and R-square analysis, and plot ...
6
votes
3
answers
12k
views
Selecting specific column in each row from array
I am trying to select specific column elements for each row of a numpy array. For example, in the following example:
In [1]: a = np.random.random((3,2))
Out[1]:
array([[ 0.75670668, 0.1283942 ],
...
42
votes
6
answers
50k
views
Pythonic way to create a numpy array from a list of numpy arrays
I generate a list of one dimensional numpy arrays in a loop and later convert this list to a 2d numpy array. I would've preallocated a 2d numpy array if i knew the number of items ahead of time, but I ...
13
votes
2
answers
18k
views
Adding arrays with different number of dimensions
Let's say I have a 2D Numpy array:
>>> a = np.random.random((4,6))
and I want to add a 1D array to each row:
>>> c = np.random.random((6,))
>>> a + c
This works. Now if ...
45
votes
3
answers
11k
views
Python web hosting: Numpy, Matplotlib, Scientific Computing
I write scientific software in Numpy/Scipy/Matplotlib. Having developed applications on my home computer, I am now interested in writing simple web applications. Example: user uploads image or audio ...
4
votes
2
answers
2k
views
Numpy: convert index in one dimension into many dimensions
Many array methods return a single index despite the fact that the array is multidimensional. For example:
a = rand(2,3)
z = a.argmax()
For two dimensions, it is easy to find the matrix indices of ...
0
votes
2
answers
3k
views
ImportError: cannot import name NumpyTest
I am trying to read a *.wav file using scipy. I do it in the following way:
import scipy.io
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
As a result I get the following error ...
2
votes
1
answer
12k
views
creating a numpy vector using 3 components
I want to create a vector in numpy using 3 components Vx, Vy, Vz as sown below. Can anyone help? Thank you
from numpy import cos, sin
Vx = cos(alpha)* cos(beta)
Vy = sin(alpha)*cos(beta)
Vz = sin(...
67
votes
6
answers
45k
views
Is the order of a Python dictionary guaranteed over iterations?
I'm currently implementing a complex microbial food-web in Python using SciPy.integrate.ode. I need the ability to easily add species and reactions to the system, so I have to code up something quite ...
4
votes
2
answers
4k
views
Displaying a cvMatrix containing complex numbers (CV_64FC2)
I'm new to OpenCV, and I would like to compare the results of a python program with my calculations in OpenCV. My matrix contains complex numbers since its the result of a cvDFT. Python handles ...