1
vote
1answer
45 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
75 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
29 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
50 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
57 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
83 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
69 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
31 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
65 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
99 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
72 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
55 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
58 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). ...
0
votes
0answers
37 views

COM restructuring an Array of Arrays returned to VBA

I am working on an application in VBA (PPT, DOC, and XLS add-ins) that uses Python to interact with SPSS Dimensions Table Object Model to automate the production of graphics & tables in MS Office ...
0
votes
1answer
69 views

Writing calculation results back into its array?

Something of a follow-up question to my last one about writing efficient python programs. I have been playing with writing my own physics simulations, and want to get away from using a billion classes ...

1 2 3 4 5 14
15 30 50 per page