Skip to content Skip to sidebar Skip to footer

How To Get All Indices Of Numpy Array, But Not In A Format Provided By Np.indices()

I would like to get all indices of 3x2 array using a NumPy function, produced in the same format, as [[x, y] for x, y in np.ndindex((3, 2))]: [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0

Solution 1:

You need to reshape and transpose it. np.ndindex() returns an array of shape (dims, input_shape). This can be done as follows

import numpy as np
your_req_in = np.indices((3, 2)).reshape(2,-1).T

Post a Comment for "How To Get All Indices Of Numpy Array, But Not In A Format Provided By Np.indices()"