2
votes
1answer
25 views

How do I vectorize this expression with Python numpy?

Given numpy arrays P(N), D(N, N), I want to compute array A(N): A_i = SUM(P_i - P_j) where j is such that D[i][j] is True A_i = 0 otherwise So, A_i = N*P_i - (P_m + P_n+...) where D[i][m], ...
3
votes
2answers
33 views

location of array of values in numpy array

Here is a small code to illustrate the problem. A = array([[1,2], [1,0], [5,3]]) f_of_A = f(A) # this is precomputed and expensive values = array([[1,2], [1,0]]) # location of values in A # if ...
6
votes
3answers
45 views

How to get the highest element in absolute value in a numpy matrix?

Here is what I am currently doing, it works but it's a little cumbersome: x = np.matrix([[1, 1], [2, -3]]) xmax = x.flat[abs(x).argmax()]
2
votes
2answers
35 views

Python script saving over input variables

I'm writing a Python script as part of research on climate change and forest fires. This may be a novice question, but I am a beginner programmer. I have large numpy arrays (1) of meteorological ...
1
vote
1answer
32 views

How to use an additive assignment with list based indexing in Numpy

I am currently trying to vectorize some code I had written using a large for loop in Python. The vectorized code is as follows: rho[pi,pj] += (rho_coeff*dt)*i_frac*j_frac rho[pi+1,pj] += ...
1
vote
3answers
51 views

removing columns from an array in Python

I have a 2D Python array, from which I would like to remove certain columns, but I don't know how many I would like to remove until the code runs. I want to loop over the columns in the original ...
3
votes
2answers
60 views

Vectorizing for loops NumPy

I'm relatively new to Python and I've got a nested for loop. Since the for loops take a while to run, I'm trying to figure out a way to vectorize this code so it can run faster. In this case, coord ...
2
votes
1answer
44 views

Getting 0 and 1s (integer bools) from a numeric numpy array in the the most efficient way

I have non-small (10^6) numpy arrays which I then make some computations on. One of the functions simply returns 0 if the value is larger than some value X or return 1 otherwise. I understand this a ...
6
votes
1answer
38 views

Share Large, Read-Only Numpy Array Between Multiprocessing Processes

I have a 60GB SciPy Array (Matrix) I must share between 5+ multiprocessing Process objects. I've seen numpy-sharedmem and read this discussion on the SciPy list. There seem to be two ...
3
votes
0answers
66 views

It should be faster, cProfile says it's faster, but the program actually runs slower

Hope you can help because this one is giving me a real headache. I'm developping a small predator-prey simulation in python(3.3), which uses a simple feedforward neural network. Today, I changed the ...
5
votes
1answer
58 views

How to remove every other element of an array in python? (The inverse of np.repeat()?)

If I have an array x, and do an np.repeat(x,2), I'm practically duplicating the array. >>> x = np.array([1,2,3,4]) >>> np.repeat(x, 2) array([1, 1, 2, 2, 3, 3, 4, 4]) How can ...
2
votes
0answers
44 views

Retrieving values of Numpy arrays stored as values of a dictionary with a list comprehension

I have a python dictionary which values are Numpy arrays. I want to create a list of a specific value of all arrays to find the maximum of them with a max() function. I was thinking about using the ...
0
votes
1answer
41 views

FFT python result [on hold]

I am trying to plot the FFT of a current waveform. I am getting as a result some that does not really make sense to me. I don't understand why I am getting 10^6 where the peak current is only 4. Any ...
1
vote
1answer
33 views

efrc gives error length-1 array can be converted to python

I'm trying to calculate the bit error rate in python with numpy. The code looks like this: EbbyNo = arange(0,16,1) ebno = 10**(EbbyNo/10) BER2 = ...
1
vote
2answers
56 views

efficiently updating a subset of a numpy array with unknown dimensionality

I have a N-dimensional numpy array, called S. Every iteration, exactly one value in this array will change. I have a second array, G that stores the gradient of S, as calculated by numpy's ...

1 2 3 4 5 389
15 30 50 per page