0
votes
0answers
9 views

Set masked pixels in a 3D RGB numpy array

I'd like to set all pixels matching some condition in a 3d numpy array (RGB image) using a mask. I have something like this: def make_dot(img, color, radius): """Make a dot of given color in the ...
1
vote
1answer
14 views

DSP - get the amplitude of all the frequencies

this question is related to : DSP : audio processing : squart or log to leverage fft? in which I was lost about the right algorithm to choose. Now, Goal : I want to get all the frequencies of my ...
1
vote
1answer
26 views

Complex number troubles with numpy

I'm attempting to translate some matlab code again and I've run into another pickle. The code itself is very simple, it's just a demonstration of a 4 node twiddle factor. Here is my attempt: from ...
4
votes
3answers
34 views

How to use numpy's hstack?

I have one large numpy.ndarray array that I want to extract the 4th and 5th columns out of and put those columns into a 2D array. The [i,0] element should be the value on the 4th column and [i,1] ...
4
votes
3answers
44 views

power spectrum by numpy.fft.fft

The figure I plot via the code below is just a peak around ZERO, no matter how I change the data. My data is just one column which records every timing points of some kind of signal. Is the time_step ...
3
votes
0answers
36 views

Cythonize two small numpy functions, help needed

The problem I'm trying to Cythonize two small functions that mostly deal with numpy ndarrays for some scientific purpose. These two smalls functions are called millions of times in a genetic ...
3
votes
2answers
46 views

solving for 5 variables using 6 linear equation using numpy

I'm trying to solve following system of equations= -14a + b + e = 0 2a - 14b + d = 0 b -14c +2d = 0 -15d + e = 0 + 2c ...
3
votes
4answers
48 views

Auto zero-padding an array

Let L be a list of, say, 55 items : L=range(55) for i in range(6): print L[10*i:10*(i+1)] The printed list will have 10 items for i = 0, 1, 2, 3 , 4, but for i = 5, it will have 5 items only. Is ...
2
votes
2answers
49 views

Mysterious IndexError - very basic issue (Python)

I'm having a problem with a bit of code, I feel like I must be missing something fundamental here. A simple example that gives the same error as I am having is as follows: from numpy import ...
2
votes
2answers
42 views

Filter an array in Python with 2 conditions

How to filter an array A according to two conditions ? A = array([1, 2.3, 4.3, 10, 23, 42, 23, 12, 1, 1]) B = array([1, 7, 21, 5, 9, 12, 14, 22, 12, 0]) print A[(B < 13)] # here we get all ...
2
votes
2answers
35 views

Find indices of N concurrences in arrays using numpy

I have an array that I obtain from using sp.distance.cdist, and such array looks as follows: [ 0. 5.37060126 2.68530063 4.65107712 2.68530063 4.65107712 2.04846297 7.41906423 ...
1
vote
1answer
30 views

problems with numpy dimensions using the [:] syntax

I've got a question... I created a numpy.array with the shape=(4,128,256,256). If I print out the following: print shape(x[:][3][1][:]) the output is shape=(256,256), not (4,256) as I expected... ...
0
votes
1answer
30 views

Unable to add matrices to tuples

New to python and numpy, searched and tried all possible solution not getting results I have a function that returns 2 matrices. I want to create an array or matrices that saves each of the matrices ...
2
votes
1answer
42 views

How to calculate a new field in python using a linear relationship

I am new to python, working with python 2.7.5, After i read a csv file in python using below code: df = csv.DictReader(open("C:\\Users\\user\\Documents\\file.csv")). I want to calculate a new ...
2
votes
1answer
30 views

Redefine a python function based on another class function based on type

I'm more of an engineer and less of a coder, but I know enough python and C++ to be dangerous. I'm creating a python vector/matrix class as a helper class based upon numpy as well as cvxopt. The ...
1
vote
2answers
39 views

scipy.optimize solution using python for the following equation

I am very new to scipy and doing data analysis in python. I am trying to solve the following regularized optimization problem and unfortunately I haven't been able to make too much sense from the ...
1
vote
1answer
25 views

Use outer function with FUN=“-” in Python

In R, you can use outer function to compute the outer product of the matrix, but can also use other operations, such as FUN="-" to operate subtractions. Is it feasible to do the same in Python and ...
3
votes
3answers
49 views

Efficiently Subtract Vector from Matrix (Scipy)

I've got a large matrix stored as a scipy.sparse.csc_matrix and want to subtract a column vector from each one of the columns in the large matrix. This is a pretty common task when you're doing things ...
0
votes
1answer
34 views

Return Rows (Array) where the first 2 columns are bigger than 0.1

An easy Example for what i want: I have a Matrix with many columns where i want to keep rows, if the cells in the first 2 columns are (both!!) bigger than 0.1 something like that: import numpy as ...
0
votes
1answer
25 views

numpy requires System Python 2.7 to install

I'm trying to learn python (in the process of installing numpy 1.8.0 in order to install BioPython), and am receiving the error "numpy requires System Python 2.7 to install" when I try to put numpy on ...
1
vote
3answers
29 views

Plotting line segments from the set of startpoints and endpoints

Suppose you have an array a with shape (n,2,2) which consists of coordinates of startpoints and endpoints of n line segmenets. How should one plot these line segments. My code doesn't work although it ...
0
votes
1answer
19 views

Using Matplotlib imshow to show GIF image

I need to show a background to a matplotlib plot using ax.imshow(). The background images that I will be using are GIF-images. Despite having PIL installed, the following code results in an error ...
2
votes
1answer
35 views

DSP : audio processing : squart or log to leverage fft?

Context : I am discovering the vast field of DSP. Yes a beginner. My goal : Applying fft on an audio array given by audiolab to get the different freqs of the signal. Question : One question : I ...
1
vote
2answers
30 views

Single index into numpy structured array subclass

I am attempting to subclass a numpy structured array so that I can add special methods to the subclass. Everything works fine until I retrieve a single index from the array. When this occurs, an ...
2
votes
1answer
20 views

Numpy: convert an array to a triangular matrix

I was looking for a built in method to convert an linear array to triangular matrix. As I failed in find one I am asking for help in implementing one. Imagine an array like: In [203]: dm Out[203]: ...
2
votes
0answers
65 views

Some python / numpy optimization possible?

I am profiling some genetic algorithm code with some nested loops and from what I see most of the time is spent in two of my functions which involve slicing and adding up numpy arrays. I tried my best ...
2
votes
3answers
57 views

np.mean() vs np.average() in Python NumPy?

Title says it all. I notice that In [30]: np.mean([1, 2, 3]) Out[30]: 2.0 In [31]: np.average([1, 2, 3]) Out[31]: 2.0 However, there should be some differences, since after all they are two ...
1
vote
0answers
34 views

Animation based on only updating colours in a plot

I have a plot which consists of great number of lines. At each step the colours of lines should get updated in the animation, but doing a for loop on lines seems to be really costly. Is there any ...
3
votes
1answer
63 views

Some i/o problems

Disclaimer: This is for an assignment. If you feel I'm just "asking you to do my homework for me" let me know and I'll ask a more broad question, or just give me hints if you can please. Ok so I've ...
1
vote
1answer
46 views

Optmizing a function scipy.optimize

I am new to python and statistical programming. For a class assignment we've been asked to implement python lasso L1 regression. This involves using a QP solver to solve . 0.5 *(x^t * H * x) + f^t * ...
0
votes
2answers
21 views

plot from a large data set into several figures

I have a large set of particle position data from a movie made by a detection camera in a physical experiment. The first column just gives the frame number, the second to fourth column is x, y, and z ...
0
votes
1answer
48 views

Interpolate on a logarithmic scale in python

To interpolate my data I currently use this function: def myinterp(x, y, der = 0, s = 0): tck = interpolate.splrep(x, y, s = sigma) xnew = np.arange(x[0], x[-1], (x[-1]-x[0])/x.size) ynew ...
3
votes
1answer
33 views

How to store wide tables in pytables / hdf5

I have data coming from a csv which has a few thousand columns and ten thousand (or so) rows. Within each column the data is of the same type, but different columns have data of different type*. ...
1
vote
2answers
73 views

How to read a big (3-4GB) file that doesn't have newlines into a numpy array?

I have a 3.3gb file containing one long line. The values in the file are comma separated and either floats or ints. Most of the values are 10. I want to read the data into a numpy array. Currently, ...
0
votes
2answers
57 views

Derivative of an array in python?

Currently I have two numpy arrays: x and y of the same size. I would like to write a function (possibly calling numpy/scipy... functions if they exist): def derivative(x, y, n = 1): # something ...
1
vote
1answer
33 views

Matplotlib 1.3.1: plot(matrix(“1,2,3”)) -> RuntimeError: maximum recursion depth exceeded

I am working with python 2.7.5 using numpy.version: 1.7.1 matplotlib.version: 1.3.1 When I start "ipython2 --pylab" and execute the following code x = matrix("1,2,3") plot(x) I get the error ...
0
votes
1answer
32 views

sort two columns in a text file with numpy.lexsort

I have a text file contain two columns and I want to sort the first column from smaller values to larger values and sort the second column according to the first column and then save it to the the ...
2
votes
3answers
37 views

Numpy Ceil and Floor “out” Argument

From the NumPy docs for ceil , the numpy.ceil function takes two arguments, the second being out. The docs don't say what this out parameter does but I assume you can set the output type this ...
0
votes
1answer
20 views

missing wedge in matplotlib contourf plot

I'm trying to plot a contour plot in matplotlib and I keep getting a missing "wedge". The following example illustrates what I'm trying to do. import numpy as np import matplotlib.pyplot as plt ...
6
votes
2answers
483 views

Python bug that only appears on embossed image using Numpy

The intention of this program is to take a ppm image and emboss it. (The entire project details can be found here) I am helping with the grading of the assignment and cannot seem to find the student's ...
0
votes
0answers
28 views

scipy.signal.resample behaves strangely

I am currently working on some signal processing (using scipy), but I encountered a strange problem and can't figure out what's wrong. Namely, I am reading some audio data from a .wav file, but have ...
1
vote
2answers
66 views

Complex eigenvectors of a symmetric matrix in MATLAB

I am facing an issue when using MATLAB eig function to compute the eigenvalues and eigenvectors of a symmetric matrix. The matrix D is 10x10 all diagonal elements = 0.45 all off-diagonal elements ...
3
votes
1answer
56 views

Understanding NumPy's Convolve

When calculating a simple moving average, numpy.convolve appears to do the job. Question: How is the calculation done when you use np.convolve(values, weights, 'valid')? When the docs mentioned ...
2
votes
1answer
61 views

Scipy - how to further optimize sparse matrix code for stochastic gradient descent

I'm working on implementing the stochastic gradient descent algorithm for recommender systems using sparse matrices with Scipy. This is how a first basic implementation looks like: N = ...
2
votes
3answers
42 views

Skip rows when reading data from file using numpy.genfromtxt

I have a data set in a file as shown below A 1 B 2 C 3 A 4 B 5 C 6 I would like to extract only rows which contain 'A'. How do I do that with numpy.genfromtxt? Is there any other function ...
4
votes
2answers
51 views

Summing each 3x3 window of a M*N matrix, into a M/3*N/3 matrix with numpy

I'm trying to implement a function that would sum (or eventually average) Each 3x3 window of a given matrix, and create a matrix 9x smaller with the result of each window. I can't figure out an ...
5
votes
3answers
81 views

How to efficiently concatenate many arange calls in numpy?

I'd like to vectorize calls like numpy.arange(0, cnt_i) over a vector of cnt values and concatenate the results like this snippet: import numpy cnts = [1,2,3] numpy.concatenate([numpy.arange(cnt) for ...
0
votes
2answers
59 views

Having problems with NumPy matrices

I'm very familiar with MATLAB, but I'm having trouble learning Python. The problem is creating an array X(idx,:) where I increment idx with each line I read and assign X(idx,:) to a row of data. The ...
2
votes
3answers
38 views

Vector (positionx,positiony,value) of a matrix python

I've got a matrix of values, and I want a vector with the positions of the matrix and the value. First idea: double-bucle and store index and value Second idea: Create a ndarray whit a sequence ...
2
votes
1answer
30 views

cimport numpy not working in cython; error message unclear (to me)

I'm new to cython (and python) and am trying to import numpy in a way that I can define variable types. My understanding is that I have to use "cimport numpy", which, however, fails, and I can't get ...

15 30 50 per page