Fix Python – Argmax of numpy array returning non-flat indices

I’m trying to get the indices of the maximum element in a Numpy array.
This can be done using numpy.argmax. My problem is, that I would like to find the biggest element in the whole array and get the indices of that.
numpy.argmax can be either applied along one axis, which is not what I want, or on the flattened array, which is kind of what I want….

Fix Python – Selecting specific rows and columns from NumPy array

I’ve been going crazy trying to figure out what stupid thing I’m doing wrong here.
I’m using NumPy, and I have specific row indices and specific column indices that I want to select from. Here’s the gist of my problem:
import numpy as np

a = np.arange(20).reshape((5,4))
# array([[ 0, 1, 2, 3],
# [ 4, 5, 6, 7],
# [ 8, 9, 10, 1….

Fix Python – Rotating a two-dimensional array in Python

In a program I’m writing the need to rotate a two-dimensional array came up. Searching for the optimal solution I found this impressive one-liner that does the job:
rotated = zip(*original[::-1])

I’m using it in my program now and it works as supposed. My problem though, is that I don’t understand how it works.
I’d appreciate if someone could exp….

Fix Python – Convert a 1D array to a 2D array in numpy

I want to convert a 1-dimensional array into a 2-dimensional array by specifying the number of columns in the 2D array. Something that would work like this:
> import numpy as np
> A = np.array([1,2,3,4,5,6])
> B = vec2matrix(A,ncol=2)
> B
array([[1, 2],
[3, 4],
[5, 6]])

Does numpy have a function that works like my made-up function ….

Fix Python – Using numpy to build an array of all combinations of two arrays

I’m trying to run over the parameters space of a 6 parameter function to study its numerical behavior before trying to do anything complex with it, so I’m searching for an efficient way to do this.
My function takes float values given in a 6-dim numpy array as input. What I tried to do initially was this:
First, I created a function that takes 2 a….

Fix Python – Difference between numpy.array shape (R, 1) and (R,)

In numpy, some of the operations return in shape (R, 1) but some return (R,). This will make matrix multiplication more tedious since explicit reshape is required. For example, given a matrix M, if we want to do numpy.dot(M[:,0], numpy.ones((1, R))) where R is the number of rows (of course, the same issue also occurs column-wise). We will get matr….