How to combine specific axes without ambuigity with numpy.ndarray

Basically I want to change the tensors provided by numpy.ndarray.

For example, I want to do something like this (latex notation)

A_ {i, j, k, l, m, n, p} β†’ A_ {i, jk, lm, np}

or

A_ {i, j, k, l, m, n, p} β†’ A_ {ij, k, l, m, np}

where A is ndarray. i, j, k, ... denotes the original axis.

so that the new axis 2 becomes a flattened version of axis 2 and 3, etc. If I just use numpy.reshape, I don’t think it knows which axes I want to combine, therefore it seems ambiguous and erroneous minded.

Is there any neat way to do this and not create another ndarray manually?

+4
source share
1 answer

reshape . .

, . 1, , .

: , "" .

+4

All Articles