借助Numpy matrix.choose()
方法,我们可以通过将包含要选择的行号索引的参数作为数组传递来从矩阵中选择元素。具有与参数中传递的大小相同的输出数组。
用法: matrix.choose()
返回: 返回元素选择的数组
范例1:
在此示例中,我们可以借助matrix.choose()
方法,我们能够从矩阵中提取选择数组。
# import the important module in python
import numpy as np
# make a matrix with numpy
gfg = np.matrix('[1, 2, 3, 4; 3, 1, 5, 6]')
# applying matrix.choose() method
geeks = np.choose([1, 0, 1, 0], gfg)
print(geeks)
输出:
[[3 2 5 4]]
范例2:
# import the important module in python
import numpy as np
# make a matrix with numpy
gfg = np.matrix('[1, 2, 3; 4, 5, 6; 7, 8, 9]')
# applying matrix.choose() method
geeks = np.choose([2, 0, 1], gfg)
print(geeks)
输出:
[[7 2 6]]
相关用法
- Python Numpy numpy.ndarray.__divmod__()用法及代码示例
- Python Numpy numpy.ndarray.__invert__()用法及代码示例
- Python Numpy numpy.ndarray.__mod__()用法及代码示例
- Python Numpy numpy.ndarray.__lshift__()用法及代码示例
- Python Numpy numpy.ndarray.__floordiv__()用法及代码示例
- Python Numpy numpy.ndarray.__add__()用法及代码示例
- Python Numpy numpy.ndarray.__sub__()用法及代码示例
- Python Numpy numpy.ndarray.__mul__()用法及代码示例
- Python Numpy numpy.ndarray.__pow__()用法及代码示例
- Python Numpy numpy.ndarray.__or__()用法及代码示例
- Python Numpy numpy.ndarray.__and__()用法及代码示例
- Python Numpy numpy.ndarray.__xor__()用法及代码示例
- Python Numpy numpy.ndarray.__iadd__()用法及代码示例
- Python Numpy numpy.ndarray.__isub__()用法及代码示例
- Python Numpy numpy.ndarray.__imul__()用法及代码示例
注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 Python | Numpy matrix.choose()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。