np.cross函数详解
numpy.cross
Reference: Official Document of Numpy
语法
numpy.cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None)
功能
Return the cross product of two (arrays of) vectors.
The cross product of a
and b
in :math:R^3
is a vector perpendicular
to both a
and b
. If a
and b
are arrays of vectors, the vectors
are defined by the last axis of a
and b
by default, and these axes
can have dimensions 2 or 3. Where the dimension of either a
or b
is
2, the third component of the input vector is assumed to be zero and the
cross product calculated accordingly. In cases where both input vectors
have dimension 2, the z-component of the cross product is returned.
计算两个向量(向量数组)的叉乘。叉乘返回的数组既垂直于a
,又垂直于b
。 如果a
,b
是向量数组,则向量在最后一维定义。该维度可以为2,也可以为3. 为2的时候会自动将第三个分量视作0补充进去计算。
Parameters
- a : array_like
Components of the first vector(s). - b : array_like
Components of the second vector(s). - axisa : int, optional
Axis ofa
that defines the vector(s). By default, the last axis. - axisb : int, optional
Axis ofb
that defines the vector(s). By default, the last axis. - axisc : int, optional
Axis ofc
containing the cross product vector(s). Ignored if
both input vectors have dimension 2, as the return is scalar.
By default, the last axis. - axis : int, optional
If defined, the axis ofa
,b
andc
that defines the vector(s)
and cross product(s). Overridesaxisa
,axisb
andaxisc
.
axisa, axisb, axisc 分别指定两个输入和输出c
的向量所在的维度。而axis则可以覆盖前三个参数,为全局指定向量所在维度。
Returns
- c : ndarray
Vector cross product(s).
Raises
- ValueError:
When the dimension of the vector(s) ina
and/orb
does not
equal 2 or 3.
当向量所在axis的dimension不为2或者3时,raise ValueError.
See Also(相关函数)
- inner : Inner product 内积
- outer : Outer product 外积
- ix_ : Construct index arrays.
Notes
… versionadded:: 1.9.0
Supports full broadcasting of the inputs.
支持广播。
Examples
Vector cross-product.
>>> x = [1, 2, 3]
>>> y = [4, 5, 6]
>>> np.cross(x, y)
array([-3, 6, -3])One vector with dimension 2.
>>> x = [1, 2]
>>> y = [4, 5, 6]
>>> np.cross(x, y)
array([12, -6, -3])Equivalently:
>>> x = [1, 2, 0]
>>> y = [4, 5, 6]
>>> np.cross(x, y)
array([12, -6, -3])Both vectors with dimension 2.
>>> x = [1,2]
>>> y = [4,5]
>>> np.cross(x, y)
array(-3)Multiple vector cross-products. Note that the direction of the cross
product vector is defined by the `right-hand rule`.
>>> x = np.array([[1,2,3], [4,5,6]])
>>> y = np.array([[4,5,6], [1,2,3]])
>>> np.cross(x, y)
array([[-3, 6, -3],[ 3, -6, 3]])The orientation of `c` can be changed using the `axisc` keyword.
>>> np.cross(x, y, axisc=0)
array([[-3, 3],[ 6, -6],[-3, 3]])Change the vector definition of `x` and `y` using `axisa` and `axisb`.
>>> x = np.array([[1,2,3], [4,5,6], [7, 8, 9]])
>>> y = np.array([[7, 8, 9], [4,5,6], [1,2,3]])
>>> np.cross(x, y)
array([[ -6, 12, -6],[ 0, 0, 0],[ 6, -12, 6]])
>>> np.cross(x, y, axisa=0, axisb=0)
array([[-24, 48, -24],[-30, 60, -30],[-36, 72, -36]])
np.cross函数详解相关推荐
- np.stack()函数详解 ==>堆叠 【类似于torch.stack()】
目录 1.来看看axis=0时,它是如何进行堆叠的:(按矩阵进行堆叠) 2.再来看看axis=1的时候:(按行进行堆叠) 3.当axis=2时(按列的的元素进行堆叠,先堆叠三个矩阵的第0个元素0,12 ...
- Python先生,你好!(6)——np.random函数详解
Python先生,你好!(6)--np.random函数详解 (一)前 言 (二)常用方法 (1)np.random.rand() (2)np.random.randn() (3)np.random. ...
- 协方差矩阵数学原理,numpy计算协方差矩阵(np.cov)函数详解与源码剖析
协方差矩阵详解以及numpy计算协方差矩阵(np.cov) 协方差矩阵详解 均值,标准差与方差 由简单的统计学基础知识,我们有如下公式: X ˉ = ∑ i = 1 n X i n \bar X{\r ...
- ndarray维度认识及np.concatenate函数详解
https://blog.csdn.net/kealennieh/article/details/82464665 np.stack() 因为stack()函数会先把参数arrays中的每个元素变成n ...
- 【知识点】Python 的np.prod函数详解
np.prod是Numpy库中的一个函数,全称为numpy.prod,它的作用是计算数组中所有元素的乘积.该函数是一个快速的计算积的方法,可以接收任意数组或矩阵作为输入,并返回这些数字的乘积. 举个例 ...
- Python 中np.prod函数详解
官方文档,输入a是数组,返回指定轴上的乘积,不指定轴默认是所有元素的乘积. 默认全部元素相乘,123*4=24 axis =0是按列乘, axis = 1是按行乘.
- python中transpose函数_对numpy中的transpose和swapaxes函数详解
transpose() 这个函数如果括号内不带参数,就相当于转置,和.T效果一样,而今天主要来讲解其带参数. 我们看如下一个numpy的数组: `arr=np.arange(16).reshape(( ...
- python数据可视化-matplotlib之散点图sactter函数详解
本文转载自-[数字的可视化:python画图之散点图sactter函数详解] 感谢博主-hefei_cyp的博客 最近开始学习Python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是 ...
- python中append函数解析_对python中的pop函数和append函数详解
对python中的pop函数和append函数详解 pop()函数 1.描述 pop() 函数用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值. 语法 pop()方法语法: list. ...
最新文章
- Atitit.数据索引 的种类以及原理实现机制 索引常用的存储结构
- python模拟鼠标点击和键盘输入的操作_Python模拟鼠标点击及键盘输入(PyUserInput)...
- d3.js 旋转图形_几何画板第9期图形的组合型运动
- RFQ(request for quotation)
- cp命令的编写——浅谈系统调用
- Python自动化之语法基础
- 彭博社:中企游说政府否决英伟达收购Arm
- 《RabbitMQ 实战指南》第三章 客户端开发向导
- 怎样手动给无线网设置一个DNS服务器地址,无线网的dns怎样设置.docx
- String str = new String(abc)创建了几个对象?结合源码解析
- nginx多域名设置和多子目录实现共用一端口
- TensorFlow中数据的feed与fetch
- PE格式第八讲,TLS表(线程局部存储)
- 学生信息管理系统java_学生信息管理系统java课程设计(含源代码)
- 应届生参加工作,什么事情越早知道越好?
- python 可迭代对象是什么_python中可迭代对象指的是什么
- 城科软件协会官网正式上线
- 如何在EXCEL中画横线并输入汉字
- cywdhd在RK平台的适配
- Element UI 弹窗遮罩层变黑
热门文章
- Linux下增加swap分区
- WorkFlow入门Step.7—Creating a FlowChart WorkFlow-For-WF4.0
- [转] VS2010中VC9.0Runtime与VC10.0Runtime在win7上装不上提示error code 1603
- win 系统 32X- 64X 任意安装方法
- RestAPI的进化之路,后端MVVM模式或许来临,通过观察者模式,后端收集前端的GET类请求,主动推送数据变更到前端
- 还在看那些老掉牙的性能优化文章么?这些最新性能指标了解下
- 容器编排技术 -- Google Computer Engine入门
- NodeJS 使用官方oracledb库连接数据库教程
- DHCP分配IP地址详细流程讲解(附图,建议PC观看)
- leetcode 字符串中的第一个唯一字符