2
votes
2answers
43 views

Numpy, python: automatically expand dimensions of arrays when broadcasting

Consider the following exercise in Numpy array broadcasting. import numpy as np v = np.array([[1.0, 2.0]]).T # column array A2 = np.random.randn(2,10) # 2D array A3 = np.random.randn(2,10,10) # 3D ...
1
vote
2answers
57 views

How to average over a 2-D array?

I have a 2-D numpy array of shape (256,128) and I would like to average every 8 rows of the 256 together so I end up with a numpy array of shape (32,128) Is there any way to average just the one ...
2
votes
1answer
410 views

joining two numpy matrices

If you have two numpy matrices, how can you join them together into one? They should be joined horizontally, so that [[0] [1] [[0][1] [1] + [0] = [1][0] ...
2
votes
1answer
59 views

Multiplication of Multidimensional matrices (arrays) in Python

First of all, I am aware that matrix and array are two different data types in NumPy. But I put both in the title to make it a general question. If you are editing this question, please feel free to ...
4
votes
2answers
116 views

Reverse an arbitrary dimension in an ndarray

I'm working with an n-dimensional array, and I'd like a way to reverse a numbered dimension. So rather than rev = a[:,:,::-1] I'd like to be able to write rev = a.reverse(dimension=2) or ...
1
vote
1answer
38 views

Creating rank 3 numpy arrays

I would like to create a rank 3 array, using numpy, such that the array resembles a stack of 9x9 rank 2 arrays. Each of these arrays will be completely filled with ones, twos, threes, etc. So, ...
3
votes
1answer
29 views

Cleanest way to merge two same-shape arrays in Numpy

We have some arrays of the same shape and want to merge them. By "merge", I mean output a new array with the sum of each i,j in each of the arrays in each position. import numpy as np first = ...
1
vote
2answers
53 views

Array Indexing in multi dimensional numpy array

I'm new to numpy and trying to understand the following example from here. I'm having trouble understanding the output of >>> palette[image] When the indexed array a is multidimensional, ...
1
vote
0answers
52 views

creating and manipulating 3d arrays

I am (very) new to python, previously a Matlab user. I try to create code to load times series into the rows of a matrix [serie1, 2, 3, etc.] and then manipulate those time series into a loop (see ...
2
votes
2answers
75 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) ...
3
votes
1answer
1k views

numpy reverse multidimensional array

What is the simplest way in numpy to reverse the most inner values of an array like this: array([[[1, 1, 1, 2], [2, 2, 2, 3], [3, 3, 3, 4]], [[1, 1, 1, 2], [2, 2, 2, 3], [3, 3, 3, ...
1
vote
1answer
73 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
108 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
49 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
101 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 = ...

1 2 3 4 5 9
15 30 50 per page