summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorUddeshya Singh <singhuddeshyaofficial@gmail.com>2018-07-09 17:26:02 +0530
committerGitHub <noreply@github.com>2018-07-09 17:26:02 +0530
commit4862c1333e8b51a409659ada3496ae1ee3675df9 (patch)
treec57c3dc3a5a8d4dd1fe6b3af3270bb16a8a79960 /numpy/lib
parentfa3079ad06b0f83a9dc24ab9df9a9461c28e9d53 (diff)
downloadnumpy-4862c1333e8b51a409659ada3496ae1ee3675df9.tar.gz
Update function_base.py
* further elaborated the return variable types * fixed the space error
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 253ce9d74..03024db3c 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -308,11 +308,14 @@ def average(a, axis=None, weights=None, returned=False):
Return the average along the specified axis. When `returned` is `True`,
return a tuple with the average as the first element and the sum
of the weights as the second element. `sum_of_weights` is of the
- same type as `average`. The result type is the type of lowest precision
- capable of representing values of both `a` and `weights` or 'float64'
- if that type would be integral. Otherwise, if `a` is non integral,
- result will be a `dtype` which is capable of representing both
- `a.dtype` and `wgt.dtype`
+ same type as `average`. The result dtype follows a genereal pattern.
+ If `weights` is None, the result dtype will be that of `a` , or `float64`
+ if `a` is integral. Otherwise, if `weights` is not None and `a` is non
+ integral, the result type will be the type of lowest precision capable of
+ representing values of both `a` and `weights` but if `a` happens to be
+ integral, the previous rules still applies but the result dtype would
+ at least be `float64`.
+
Raises
------
ZeroDivisionError
@@ -348,9 +351,11 @@ def average(a, axis=None, weights=None, returned=False):
>>> np.average(data, axis=1, weights=[1./4, 3./4])
array([ 0.75, 2.75, 4.75])
>>> np.average(data, weights=[1./4, 3./4])
+
Traceback (most recent call last):
...
TypeError: Axis must be specified when shapes of a and weights differ.
+
>>> a = np.ones(5, dtype=np.float128)
>>> w = np.ones(5, dtype=np.complex64)
>>> avg = np.average(a, weights=w)