Skip to content
Advertisement

Tag: numpy

Splicing NumPy arrays

I am having a problem splicing together two arrays. Let’s assume I have two arrays: When I do vstack((a,b)) I get and if I do hstack((a,b)) I get: But what I really want is: How do I accomplish this without using for loops (it needs to be fast)? Answer column_stack.

Numpy and line intersections

How would I use numpy to calculate the intersection between two line segments? In the code I have segment1 = ((x1,y1),(x2,y2)) and segment2 = ((x1,y1),(x2,y2)). Note segment1 does not equal segment2. So in my code I’ve also been calculating the slope and y-intercept, it would be nice if that could be avoided but I don’t know of a way how.

How find values in an array that meet two conditions using Python

I have an array and I want to find the indices of the element s that meet two conditions i.e. I can use numpy.nonzero(a>3) or numpy.nonzero(a<8) but not numpy.nonzero(a>3 and a<8) which gives the error: When I try to use any or all I get the same error. Is it possible to combine two conditional tests to get the ans?

How do I calculate percentiles with python/numpy?

Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy array? I am looking for something similar to Excel’s percentile function. I looked in NumPy’s statistics reference, and couldn’t find this. All I could find is the median (50th percentile), but not something more specific. Answer You might be interested in the SciPy Stats package. It

Matplotlib runs out of memory when plotting in a loop

I have a fairly simple plotting routine that looks like this: When I plot this in single iterations, it works fine. However, the moment I put it in a loop, matplotlib throws a hissy fit… This happens on iteration 2 (counting from 1), if that makes a difference. The code is running on Windows XP 32-bit with python 2.5 and

Convert NumPy array to Python list

How do I convert a NumPy array into a Python List? Answer Use tolist(): Note that this converts the values from whatever numpy type they may have (e.g. np.int32 or np.float32) to the “nearest compatible Python type” (in a list). If you want to preserve the numpy data types, you could call list() on your array instead, and you’ll end

The Assignment Problem, a NumPy function?

Since an assignment problem can be posed in the form of a single matrix, I am wondering if NumPy has a function to solve such a matrix. So far I have found none. Maybe one of you guys know if NumPy/SciPy has an assignment-problem-solve function? Edit: In the meanwhile I have found a Python (not NumPy/SciPy) implementation at http://software.clapper.org/munkres/. Still

Can’t import Numpy in Python

I’m trying to write some code that uses Numpy. However, I can’t import it: I tried the suggestions in this question: and I searched for files named numpy in that path: But nothing came up. So… Are there any other places in which Python modules are commonly installed? How can I install numpy locally in my account, if it turns

Advertisement