numpy

comparing row in numpy array

Hi, I have a 2d numpy array of bools, and I'd like to know how many unique rows my data set contains and the frequency of each row. The only way I could solve this problem is by converting my whole data set into a string and then do the comparison, but surely there must be a better way to do this. Any help is appreciated. def getUnique...

Linear Regression with Python numpy

Hey all- I'm trying to make a simple linear regression function but continue to encounter a numpy.linalg.linalg.LinAlgError: Singular matrix error Existing function (with debug): def makeLLS(inputData, targetData): print "In makeLLS:" print " Shape inputData:",inputData.shape print " Shape targetData:",targetData.s...

build recent numpy on recent ubuntu

Hi How do I build numpy 1.5 on ubuntu 10.10? The instructions I found seems outdated or not clear. Thanks ...

fitting exponential decay with no initial guessing

Does anyone know a scipy/numpy module which will allow to fit exponential decay to data? Google search returned a few blog posts, for example - http://exnumerus.blogspot.com/2010/04/how-to-fit-exponential-decay-example-in.html , but that solution requires y-offset to be pre-specified, which is not always possible EDIT: curve_fit wor...

ImportError when installing NumPy for Python 2.7

EDIT: after reading this http://projects.scipy.org/numpy/ticket/1322 it seems that the NumPy version I am using doesn't work with Mac OS 10.5.x. Does anyone have access to a version of NumPy that works with Mac OS 10.5? I can't get it to compile either. Original post ... I am trying to use NumPy, but I'm having difficulty installing ...

PyTable Column Order

Is there a way to create a PyTable with a specific column order? By default, the columns are alphabetically ordered when using both dictionary or class for schema definition for the call to createTable(). My need is to establish a specific order and then use numpy.genfromtxt() to read and store my data from text. Unfortunately, my text ...

Display NumPy array as continuously updating image with Glumpy

I've got a simulation model running in Python using NumPy and SciPy and it produces a 2D NumPy array as the output each iteration. I've been displaying this output as an image using matplotlib and the imshow function. However, I've found out about Glumpy, and on its documentation page it says: Thanks to the IPython shell, glumpy can be ...

Migrating from Stata to Python

Some coworkers who have been struggling with STATA 11 are asking for my help to try to automate their laborious work. they mainly use 3 commands in stata: tsset (sets a time series analysis) as in: tsset year_column, yeary varsoc (Obtain lag-order selection statistics for VARs) as in: varsoc column_a column_b vec (vecto...

method signature for jacobian func in scipy leastsq

Hi, Can anyone provide an example of providing a jacobian to a leastsq function in scipy? ( http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html#scipy.optimize.leastsq ) I can't figure out the method signature they want - they say it should be a function, yet it's very hard to figure out what input parameter...

Mapping function to numpy array, varying a parameter

First, let me show you the codez: a = array([...]) for n in range(10000): func_curry = functools.partial(func, y=n) result = array(map(func_curry, a)) do_something_else(result) ... What I'm doing here is trying to apply func to an array, changing every time the value of the func's second parameter. This is SLOOOOW (cre...

How to find the local minima of a smooth multidimensional array in NumPy efficiently?

Say I have an array in NumPy containing evaluations of a continuous differentiable function, and I want to find the local minima. There is no noise, so every point whose value is lower than the values of all its neighbors meets my criterion for a local minimum. I have the following list comprehension which works for a two-dimensional ar...

Numpy.array indexing question

I am trying to create a 'mask' of a numpy.array by specifying certain criteria. Python even has nice syntax for something like this: >> A = numpy.array([1,2,3,4,5]) >> A > 3 array([False, False, False, True, True]) But if I have a list of criteria instead of a range: >> A = numpy.array([1,2,3,4,5]) >> crit = [1,3,5] I can't do this...

What does ... mean in numpy code?

And what is it called? I don't know how to search for it; I tried calling it ellipsis with the Google. I don't mean in interactive output when dots are used to indicate that the full array is not being shown, but as in the code I'm looking at, xTensor0[...] = xVTensor[..., 0] From my experimentation, it appears to function the simila...

Speed up NumPy loop

I'm running a model in Python and I'm trying to speed up the execution time. Through profiling the code I've found that a huge amount of the total processing time is spent in the cell_in_shadow function below. I'm wondering if there is any way to speed it up? The aim of the function is to provide a boolean response stating whether the s...

Sum one row of a NumPy array

I'd like to sum one particular row of a large NumPy array. I know the function array.max() will give the maximum across the whole array, and array.max(1) will give me the maximum across each of the rows as an array. However, I'd like to get the maximum in a certain row (for example, row 7, or row 29). I have a large array, so getting the...

Difference between random draws from scipy.stats....rvs and numpy.random

Hi, It seems if it is the same distribution, then random draws from numby.random is faster than that from scipy.stats.....rvs. I was wondering what causes the speed difference between the two. -Joon ...

How does numpy zeros implement the parameter shape?

I want to implement a similar function, and want to accept an array or number that I pass to numpy.ones. Specifically, I want to do this: def halfs(shape): shape = numpy.concatenate([2], shape) return 0.5 * numpy.ones(shape) Example input-output pairs: # default In [5]: beta_jeffreys() Out[5]: array([-0.5, -0.5]) # scalar I...

Numpy array broadcasting with vector parameters

Is it possible to do array broadcasting in numpy with parameters that are vectors? For example, I know that I can do this def bernoulli_fraction_to_logodds(fraction): if fraction == 1.0: return inf return log(fraction / (1 - fraction)) bernoulli_fraction_to_logodds = numpy.frompyfunc(bernoulli_fraction_to_logodds, 1, 1)...

Efficient way to count unique elements in array in numpy/scipy in Python

I have a scipy array, e.g. a = array([[0, 0, 1], [1, 1, 1], [1, 1, 1], [1, 0, 1]]) I want to count the number of occurrences of each unique element in the array. For example, for the above array a, I want to get out that there is 1 occurrence of [0, 0, 1], 2 occurrences of [1, 1, 1] and 1 occurrence of [1, 0, 1]. One way I thought of...

Going from numpy array to itk Image

I have a numpy array and want to convert it into an ITK image for further processing. How do I do this without using the PyBuffer extension to WrapITK. I can't use that because I get a bunch of errors when compiling: .../ExternalProjects/PyBuffer/itkPyBuffer.txx: In static member function ‘static PyObject* itk::PyBuffer<TImage>::GetAr...