python numpy ufunc.reduce(self, a, axis=0, dtype=None, out=None, keepdims=False)函数.(连续执行原始运算对值聚合)
生活随笔
收集整理的這篇文章主要介紹了
python numpy ufunc.reduce(self, a, axis=0, dtype=None, out=None, keepdims=False)函数.(连续执行原始运算对值聚合)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
def reduce(self, a, axis=0, dtype=None, out=None, keepdims=False): # real signature unknown; restored from __doc__"""reduce(a, axis=0, dtype=None, out=None, keepdims=False)Reduces `a`'s dimension by one, by applying ufunc along one axis.通過沿一個軸應用ufunc將`a`的尺寸減小一倍。Let :math:`a.shape = (N_0, ..., N_i, ..., N_{M-1})`. Then:math:`ufunc.reduce(a, axis=i)[k_0, ..,k_{i-1}, k_{i+1}, .., k_{M-1}]` =the result of iterating `j` over :math:`range(N_i)`, cumulatively applyingufunc to each :math:`a[k_0, ..,k_{i-1}, j, k_{i+1}, .., k_{M-1}]`.For a one-dimensional array, reduce produces results equivalent to:::令a.shape =(N_0,...,N_i,...,N_ {M-1})`。 然后:ufunc.reduce(a,axis = i)[k_0,..,k_ {i-1},k_ {i + 1},..,k_ {M-1}]`=的結果在:math:`range(N_i)`上迭代`j`,將ufunc累積應用于每個:math:`a [k_0,..,k_ {i-1},j,k_ {i + 1},.., k_ {M-1}]`。 對于一維數組,reduce產生的結果等于:::r = op.identity # op = ufuncfor i in range(len(A)):r = op(r, A[i])return rFor example, add.reduce() is equivalent to sum().例如,add.reduce()等同于sum()。Parameters----------a : array_likeThe array to act on.要作用的數組。axis : None or int or tuple of ints, optionalAxis or axes along which a reduction is performed.The default (`axis` = 0) is perform a reduction over the firstdimension of the input array. `axis` may be negative, inwhich case it counts from the last to the first axis.進行縮小的一個或多個軸。 默認值(“ axis” = 0)是對輸入數組的第一維進行縮減。 “軸”可能為負,在這種情況下,它從最后一個軸開始計數。.. versionadded:: 1.7.0If this is `None`, a reduction is performed over all the axes.If this is a tuple of ints, a reduction is performed on multipleaxes, instead of a single axis or all the axes as before.如果為“無”,則對所有軸進行歸約。 如果這是一個整數元組,則在多個軸上執行歸約,而不是像以前那樣在單個軸或所有軸上執行歸約。For operations which are either not commutative or not associative,doing a reduction over multiple axes is not well-defined. Theufuncs do not currently raise an exception in this case, but willlikely do so in the future.對于非交換或非關聯運算,在多個軸上進行歸約的定義不明確。 在這種情況下,ufunc當前不會引發異常,但將來可能會引發異常。dtype : data-type code, optionalThe type used to represent the intermediate results. Defaultsto the data-type of the output array if this is provided, orthe data-type of the input array if no output array is provided.用于表示中間結果的類型。 如果提供此參數,則默認為輸出數組的數據類型;如果不提供輸出數組,則默認為輸入數組的數據類型。out : ndarray, None, or tuple of ndarray and None, optionalA location into which the result is stored. If not provided or `None`,a freshly-allocated array is returned. For consistency with:ref:`ufunc.__call__`, if given as a keyword, this may be wrapped in a1-element tuple.結果存儲的位置。 如果未提供或沒有,則返回一個新分配的數組。 為了與ufunc .__ call__保持一致,如果作為關鍵字給出,則可以將其包裝在1元素元組中。.. versionchanged:: 1.13.0Tuples are allowed for keyword argument.keepdims : bool, optionalIf this is set to True, the axes which are reduced are leftin the result as dimensions with size one. With this option,the result will broadcast correctly against the original `arr`.如果將其設置為True,則縮小的軸將保留為尺寸1的尺寸。 使用此選項,結果將針對原始`arr`正確廣播。.. versionadded:: 1.7.0Returns-------r : ndarrayThe reduced array. If `out` was supplied, `r` is a reference to it.精簡數組。 如果提供了`out`,則`r`是對它的引用。Examples-------->>> np.multiply.reduce([2,3,5])30A multi-dimensional array example:>>> X = np.arange(8).reshape((2,2,2))>>> Xarray([[[0, 1],[2, 3]],[[4, 5],[6, 7]]])>>> np.add.reduce(X, 0) # 次外層相加array([[ 4, 6],[ 8, 10]])>>> np.add.reduce(X) # confirm: default axis value is 0 如果不指定軸,則默認為0(次外層)array([[ 4, 6],[ 8, 10]])>>> np.add.reduce(X, 1)array([[ 2, 4],[10, 12]])>>> np.add.reduce(X, 2)array([[ 1, 5],[ 9, 13]])"""pass
參考文章:numpy高級應用—ufunc
總結
以上是生活随笔為你收集整理的python numpy ufunc.reduce(self, a, axis=0, dtype=None, out=None, keepdims=False)函数.(连续执行原始运算对值聚合)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python numpy Broadca
- 下一篇: websocket python爬虫_p