scipy

SWIG + SCIPY = Import Error on PyArray_TYPE

Hey gang, so I've written a swig wrapper for some C code. I'm trying to bridge the gap between scipy arrays and C arrays, which I know is messy. After a clean compilation (well...not including some warnings...) I'm getting this issue when I load the python-swig-c module: undefined symbol: PyArray_TYPE I've added my swig interface file...

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...

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...

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...

SciPy's non-linear least square

Dear All. I tried to do bundle adjustment by python. So I'm test non-linear least square module. Then I wrote code like below. I want to get right Pmat represents camera projection matrix for three cameras. But I have an error,"ValueError: object too deep for desired array". Anyone who can give clue to solve this issue? Regards, ...

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 ...

Performing GLM within python script on windows 7 64

Dear Stackoverflow users, I'm trying to perform GLM (Generalized linear model) repeatedly within a python script (within a loop). 1- I tried to use Stats within Scipy glm function but description is quite inexistant and I think I did not use it well --> error message "ValueError: only ttest_ind implemented". I searched within stats.py f...

Properly evaluating double integral in python

Hello. I am trying to compute a definite double integral using scipy. The integrand is a bit complicated, as it contains some probability distributions to give weight to how likely is each value of x and y (like a mixture model). The following code evaluated to a negative number, but it should be bound by [0,1]. Additionally, it took abo...

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...

plotting a parabola within part of a repeating signal using numpy

I have a repeating signal that varies a little bit with each cycle of a process that repeats roughly every second, though the duration and the contents of each cycle vary from each other a little bit within some parameters. There are a thousand x,y coordinates for every second of my signal data. A small, but important, segment of the d...

Python/Numpy: Convert list of bools to unsigned int

What is the fastest (or most "Pythonic") way to convert x = [False, False, True, True] into 12? (If there is such a way.) What if x were instead a numpy.array of bools? Is there a special command for that? I have a large m-by-n array of booleans, where each n-element row represents a single low-dimensional hash of a high-dimensiona...