2d numpy indexing by another array
So, I have a 2d array
Flattening groups of indices in a numpy array
Suppose I have a four-dimensional array and I would like to flatten the first two indices and the last two indices. For example, with a 2x2x2x2 array, this would yield a (2×2)x(2×2)=4×4 array. How can I do this?
creating a 2D numpy array from the min of the i-th and j-th elements of a 1D array
Given a 1D array, I would like to create a 2D numpy array where the element at arr2d[i,j]
is equal to min(arr1d[i], arr1d[j])
.
Storing numpy array in raw binary file
How to store a 2D numpy ndarray
in raw binary format? It should become a raw array of float32 values, in row-major order, no padding, without any headers.