Numpy 的 cross(~)
方法计算两个输入数组的叉积。
参数
1. a
| array-like
第一个输入数组。
2. b
| array-like
第二个输入数组。
3. axisa
| int
| optional
用于计算数组 a
叉积的轴。仅当您处理多维数组(例如二维数组)时才需要考虑这一点。默认情况下,将使用最后一个轴。
4. axisb
| int
| optional
用于计算数组 b
叉积的轴。仅当您处理多维数组(例如二维数组)时才需要考虑这一点。默认情况下,将使用最后一个轴。
返回值
表示两个输入数组的叉积的 Numpy 数组。
例子
基本用法
x = [1, 2, 3]
y = [4, 5, 6]
np.cross(x, y)
array([-3, 6, -3])
size-two 数组的叉积
我们还可以计算大小为 2 的数组的叉积:
x = [1, 2]
y = [3, 4]
np.cross(x,y)
array(-2)
在这里,我们计算了点积 (1*4)-(2*3)=-2
。
size-two 数组和 size-three 数组的叉积
x = [1, 2, 3]
y = [4, 5]
np.cross(x,y)
array([-15, 12, -3])
这里假设y
为[4, 5, 0]
,即z-component补0。
二维数组的叉积
x = [[1,2,3], [4,5,6]]
y = [[5,6], [7,8], [9,10]]
np.cross(x, y, axisa=1, axisb=0) # axis=1 <- row wise, axis=0 <- column-wise
array([[-3, 6, -3],
[ 2, -4, 2]])
为了方便您的观看,这里对 x
和 y
进行了美化:
x = [[1, 2, 3], y = [[5, 6]
[4, 5, 6]] [7, 8]
[9, 10]]
我们在这里所做的计算如下:
np.cross([1,2,3], [5,7,9]) # [-3, 6, -3]
np.cross([4,5,6], [6,8,10]) # [ 2, -4, 2]
相关用法
- Python Pandas crosstab方法用法及代码示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代码示例
- Python NumPy char find方法用法及代码示例
- Python cudf.Series.ceil用法及代码示例
- Python cudf.core.column.string.StringMethods.endswith用法及代码示例
- Python cuxfilter.charts.datashader.heatmap用法及代码示例
- Python cusignal.windows.windows.hann用法及代码示例
- Python cudf.DataFrame.isin用法及代码示例
- Python cudf.core.column.string.StringMethods.title用法及代码示例
- Python codecs.decode()用法及代码示例
- Python cuml.metrics.pairwise_distances.pairwise_distances用法及代码示例
- Python collections.somenamedtuple._replace用法及代码示例
- Python cuxfilter.charts.panel_widgets.int_slider用法及代码示例
- Python cudf.DataFrame.rmul用法及代码示例
- Python cudf.Series.max用法及代码示例
- Python cmp()用法及代码示例
- Python cudf.DatetimeIndex.dayofweek用法及代码示例
- Python cudf.DataFrame.apply用法及代码示例
- Python cucim.skimage.feature.shape_index用法及代码示例
- Python cuml.neighbors.KNeighborsClassifier用法及代码示例
- Python cudf.core.column.string.StringMethods.contains用法及代码示例
- Python cuxfilter.charts.datashader.line用法及代码示例
- Python cudf.core.column.string.StringMethods.rsplit用法及代码示例
- Python cudf.DataFrame.exp用法及代码示例
- Python cudf.Series.head用法及代码示例
注:本文由纯净天空筛选整理自Isshin Inada大神的英文原创作品 NumPy | cross method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。