arr = np.array([[3,6,6],[4,5,1]])
np.ravel_multi_index(arr, (7,6))
## array([22, 41, 37])
r = 7
c = 6
print(np.arange(r*c))
print(np.arange(r*c).reshape(r,c))
print(np.arange(r*c).reshape(r,c)[[3,6,6],[4,5,1]])
## [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41]
## [[ 0 1 2 3 4 5]
## [ 6 7 8 9 10 11]
## [12 13 14 15 16 17]
## [18 19 20 21 22 23] (3,4)
## [24 25 26 27 28 29]
## [30 31 32 33 34 35]
## [36 37 38 39 40 41]] (6,5) (6,1)
## [22 41 37] (3*6+4, 6*6+5, 6*6+1)
https://numpy.org/doc/stable/reference/generated/numpy.ravel_multi_index.html
numpy.ravel_multi_index(multi_index, dims, mode='raise', order='C')
Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.
- Parameters :
> multi_index : tuple of array_like
A tuple of integer arrays, one array for each dimension.
> dim : stuple of ints
The shape of array into which the indices from multi_index apply.
> mode{‘raise’, ‘wrap’, ‘clip’}, optional
Specifies how out-of-bounds indices are handled. Can specify either one mode or a tuple of modes, one mode per index.
‘raise’ – raise an error (default)
‘wrap’ – wrap around
‘clip’ – clip to the range
In ‘clip’ mode, a negative index which would normally wrap will clip to 0 instead.
> order{‘C’, ‘F’}, optional
Determines whether the multi-index should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.
- Returns
> raveled_indices : ndarray
An array of indices into the flattened version of an array of dimensions dims.
'Library' 카테고리의 다른 글
sklearn - template (0) | 2021.07.01 |
---|---|
sklearn - Scaler (0) | 2021.06.23 |
Scikit-allel (0) | 2020.11.06 |
sklearn - Standardization (0) | 2020.11.05 |
Scikit-learn, sklearn (0) | 2020.11.04 |
댓글