خرید بک لینک

Vote count: 0

I have a numpy.array, called grid, with shape:

grid.shape = [N, M_1, M_2, ..., M_N]

The values of N, M_1, M_2, ..., M_N are known only after initialization.

For this example, let's say N=3 and M_1 = 20, M_2 = 17, M_3 = 9

I am trying to loop over this array, as follows:

for indices, val in np.ndenumerate(grid[0]):
    print indices
    _some_func_with_N_arguments(*grid[:, indices])

However grid[:, indices] retus an array which is 3 x 3 x 17 x 9, whereas I want it to be an array of three elements only, much like:

grid[:, indices[0], indices[1], indices[2]]

which however I caot implement like that, because I don't know a-priori what is the length of indices.

I am using python 2.7, but a version-agnostic implementation is welcome :-)

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 24 فروردين 1395 ساعت: 8:07

صفحه بندی