numpy.ix_()函數根據多個序列構造一個開放網格。此函數采用N個一維序列,並返回N個輸出,每個輸出具有N個維度,因此,除了一個維度外,其他所有形狀均為1,並且具有非單位形狀值的維度在所有N個維度中循環。
用法: numpy.ix_(args)
參數:
args :[1-D sequences] Each sequence should be of integer or boolean type.
Return :[tuple of ndarrays] N arrays with N dimensions each, with N the number of input sequences. Together these arrays form an open mesh.
代碼1:
# Python program explaining
# numpy.ix_() function
# importing numpy as geek
import numpy as geek
gfg = geek.ix_([0, 1], [2, 4])
print (gfg)
輸出:
(array([[0], [1]]), array([[2, 4]]))
代碼2:
# Python program explaining
# numpy.ix_() function
# importing numpy as geek
import numpy as geek
arr = geek.arange(10).reshape(2, 5)
print("Initial array:\n", arr)
ixgrid = geek.ix_([0, 1], [2, 4])
print("New array:\n", arr[ixgrid])
輸出:
Initial array: [[0 1 2 3 4] [5 6 7 8 9]] New array: [[2 4] [7 9]]
相關用法
- Python Wand function()用法及代碼示例
- Python str()用法及代碼示例
- Python tell()用法及代碼示例
- Python cmp()用法及代碼示例
- Python oct()用法及代碼示例
- Python sum()用法及代碼示例
- Python id()用法及代碼示例
- Python hex()用法及代碼示例
- Python dir()用法及代碼示例
- Python now()用法及代碼示例
- Python int()用法及代碼示例
- Python map()用法及代碼示例
- Python ord()用法及代碼示例
- Python frexp()用法及代碼示例
- Python cmath.sin()用法及代碼示例
- Python join()用法及代碼示例
- Python Union()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.ix_() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。