Tagged Questions
2
votes
2answers
47 views
Iterating two arrays, without nditer, in numpy?
Consider a specification of numpy arrays, typical for specifying matplotlib plotting data:
t = np.arange(0.0,1.5,0.25)
s = np.sin(2*np.pi*t)
Basically, this stores the x coordinates of our (x,y) ...
0
votes
3answers
49 views
Excel CSV help Python
I have the following CSV file:
How do I import the numbers only into an array in python one row at a time? No date, no string.
My code:
import csv
def test():
out = open("example.csv","rb")
...
1
vote
1answer
67 views
Selecting some dimensions from a multi-dimensional array
I have a 4-D array, and I need to process all 1-D vectors from this array along a given dimension. This works well:
def myfun(arr4d,selected_dim): # selected_dim can only be 2 or 3
...
2
votes
6answers
91 views
Python: Find number of occurrences of given array within two-dimensional array
How best to find the number of occurrences of a given array within a set of arrays (two-dimensional array) in python (with numpy)?
This is (simplified) what I need expressed in python code:
patterns ...
0
votes
2answers
38 views
Numpy array subset - unexpected behaviour
I'm trying to copy a subset of a numpy array (to do image background subtraction - but that's by the by). I don't understand what's wrong with the following - I've demonstrated it interactively ...
1
vote
1answer
63 views
numpy divide row by row sum
How can I divide a numpy array row by the sum of all values in this row?
This is one example. But I'm pretty sure there is a fancy and much more efficient way of doing this:
import numpy as np
e = ...
3
votes
1answer
58 views
Dictionary of 4-D numpy array: how to optimize?
I have a problem of performances in inizalizing a dictionary of 4-D numpy tensor.
I have a list of coefficients names:
cnames = ['CN', 'CM', 'CA', 'CY', 'CLN' ...];
that is not fixed-size (it ...
2
votes
2answers
106 views
NumPy: How to collapse N-dimensional array along a single dimension using argmin/max output?
Is there a straight-forward way to use the output of calling NumPy's argmax or argmin functions on a single dimension of an N-D array to define an index into that array?
This is probably best ...
0
votes
4answers
106 views
python: convert 2 dimension list of string to float
I have a 2 dimension list of type string I'm trying to convert it to int. Things I've tried so far:
[[float(i) for i in lst[j] for j in lst]
with a for loop:
for i in range(len(lst)):
for j ...
2
votes
2answers
34 views
Setting values in matrices - Python
I made i matrix 5x3
field = []
fields = []
for i in range(0,5):
for j in range(0,3):
x = 1
field.append(x)
fields.append(field)
When i want to change one ...
2
votes
2answers
77 views
How to return an array of at least 4D: efficient method to simulate numpy.atleast_4d
numpy provides three handy routines to turn an array into at least a 1D, 2D, or 3D array, e.g. through numpy.atleast_3d
I need the equivalent for one more dimension: atleast_4d. I can think of ...
0
votes
1answer
102 views
Basic Python programming help needed involving arrays and random locations
Consider a 100X100 array.
Generate an array of several thousand random locations within
such an array, e.g. (3,75) and (56, 34).
Calculate how often one of your random locations falls within 15
...
2
votes
3answers
78 views
Calculate mean across dimension in a 2D array
I have an array a like this:
a=[]
a.append([40,10])
a.append([50,11])
so it looks like this:
>>> a
[[40, 10], [50, 11]]
I need to calculate the mean for each dimension separately, the ...
2
votes
2answers
60 views
Filtering a numpy meshgrid
I would like to filter the values of a numpy meshgrid:
X,Y = np.mgrid[-10:10,-10:10]
in this case, I would like to remove all coordinates for which x**2 + y**2 <= 2. However, when I try to ...
1
vote
3answers
60 views
Copying Data Between 3D Numpy Arrays Where A Condition Is True
I'd like to copy data from one 3D array to another 3D array at the indices where a condition is true for a different 2D array. All three arrays have the same first two dimensional shapes (x,y coords).
...