- 教程
- 介绍
- 环境
- Ndarray 对象(Ndarray Object)
- 数据类型
- 数组属性(Array Attributes)
- 阵列创建例程(Array Creation Routines)
- 来自现有数据的数组(Array from Existing Data)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 广播(Broadcasting)
- 迭代数组(Iterating Over Array)
- 数组操作(Array Manipulation)
- Binary 运算符
- 字符串函数(String Functions)
- 数学函数(Mathematical Functions)
- 算术运算(Arithmetic Operations)
- 统计函数(Statistical Functions)
- 统计函数(Statistical Functions)
- 字节交换(Byte Swapping)
- 副本和视图(Copies & Views)
- 矩阵库(Matrix Library)
- 线性代数(Linear Algebra)
- Matplotlib(Matplotlib)
- 使用Matplotlib的直方图(Histogram Using Matplotlib)
- I/O with NumPy
- 有用的资源
- reshape
- flat
- flatten
- ravel
- transpose
- ndarray.T
- rollaxis
- swapaxes
- broadcast
- broadcast_to
- expand_dims
- squeeze
- concatenate
- stack
- hstack
- vstack
- split
- hsplit
- vsplit
- resize
- append
- insert
- delete
- unique
- bitwise_and
- bitwise_or
- invert
- left_shift
- right_shift
- add()
- multiply()
- center()
- capitalize()
- title()
- lower()
- upper()
- split()
- splitlines()
- strip()
- join()
- replace()
- decode()
- encode()
- dot
- vdot
- inner
- matmul
- determinant
- solve
- inv
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
broadcast
如前所述,NumPy内置了对广播的支持。 该功能模仿广播机制。 它返回一个对象,该对象封装了一个数组与另一个数组相互广播的结果。
该函数将两个数组作为输入参数。 以下示例说明了它的用法。
例子 (Example)
import numpy as np
x = np.array([[1], [2], [3]])
y = np.array([4, 5, 6])
# tobroadcast x against y
b = np.broadcast(x,y)
# it has an iterator property, a tuple of iterators along self's "components."
print 'Broadcast x against y:'
r,c = b.iters
print r.next(), c.next()
print r.next(), c.next()
print '\n'
# shape attribute returns the shape of broadcast object
print 'The shape of the broadcast object:'
print b.shape
print '\n'
# to add x and y manually using broadcast
b = np.broadcast(x,y)
c = np.empty(b.shape)
print 'Add x and y manually using broadcast:'
print c.shape
print '\n'
c.flat = [u + v for (u,v) in b]
print 'After applying the flat function:'
print c
print '\n'
# same result obtained by NumPy's built-in broadcasting support
print 'The summation of x and y:'
print x + y
其输出如下 -
Broadcast x against y:
1 4
1 5
The shape of the broadcast object:
(3, 3)
Add x and y manually using broadcast:
(3, 3)
After applying the flat function:
[[ 5. 6. 7.]
[ 6. 7. 8.]
[ 7. 8. 9.]]
The summation of x and y:
[[5 6 7]
[6 7 8]
[7 8 9]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论