當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python mxnet.ndarray.indexing_key_expand_implicit_axes用法及代碼示例

用法:

mxnet.ndarray.indexing_key_expand_implicit_axes(key, shape)

通過添加 slice(None) 使隱式軸顯式,並通過 nonzero 將布爾數組轉換為整數數組。

例子

>>> shape = (3, 4, 5)
>>> indexing_key_expand_implicit_axes(np.s_[2, 1, 1], shape)
(2, 1, 1)
>>> indexing_key_expand_implicit_axes(np.s_[0], shape)
(0, slice(None, None, None), slice(None, None, None))
>>> indexing_key_expand_implicit_axes(np.s_[0, ...], shape)  # equivalent
(0, slice(None, None, None), slice(None, None, None))
>>> indexing_key_expand_implicit_axes(np.s_[:2, None, 0, ...], shape)
(slice(None, 2, None), None, 0, slice(None, None, None))
>>> bool_array = np.array([[True, False, True, False],
                           [False, True, False, True],
                           [True, False, True, False]], dtype=np.bool)
>>> indexing_key_expand_implicit_axes(np.s_[bool_array, None, 0:2], shape)
(array([0, 0, 1, 1, 2, 2], dtype=int64), array([0, 2, 1, 3, 0, 2], dtype=int64), None, slice(None, 2, None))

相關用法


注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 mxnet.ndarray.indexing_key_expand_implicit_axes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。