numpy.broadcast#
- class numpy.broadcast[原始碼]#
產生一個模仿廣播 (broadcasting) 的物件。
- 參數:
- in1, in2, …array_like
輸入參數。
- 回傳:
- bbroadcast 物件
將輸入參數彼此廣播,並回傳一個封裝結果的物件。 除此之外,它還具有
shape
和nd
屬性,並且可以用作迭代器。
範例
手動添加兩個向量,使用廣播
>>> import numpy as np >>> x = np.array([[1], [2], [3]]) >>> y = np.array([4, 5, 6]) >>> b = np.broadcast(x, y)
>>> out = np.empty(b.shape) >>> out.flat = [u+v for (u,v) in b] >>> out array([[5., 6., 7.], [6., 7., 8.], [7., 8., 9.]])
與內建廣播比較
>>> x + y array([[5, 6, 7], [6, 7, 8], [7, 8, 9]])
- 屬性:
方法
reset
()重設廣播結果的迭代器。