summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorUddeshya Singh <singhuddeshyaofficial@gmail.com>2018-06-16 12:36:43 +0530
committermattip <matti.picus@gmail.com>2018-06-28 10:25:01 -0700
commite47fd774235ca25b5f1a20884cc9caea9fba81bb (patch)
tree20c3b445dd46a66770fd9e7b1562368b854b6787 /numpy/lib/function_base.py
parenta9b01a2d24aa3aa5c523df6b97467db1c92607d4 (diff)
downloadnumpy-e47fd774235ca25b5f1a20884cc9caea9fba81bb.tar.gz
DOC: update return type description for average
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 26ef3e235..48b2df3b8 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -307,10 +307,12 @@ def average(a, axis=None, weights=None, returned=False):
average, [sum_of_weights] : array_type or double
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. The return type is `Float`
- if `a` is of integer type, otherwise it is of the same type as `a`.
- `sum_of_weights` is of the same type as `average`.
-
+ 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`
Raises
------
ZeroDivisionError
@@ -326,7 +328,8 @@ def average(a, axis=None, weights=None, returned=False):
ma.average : average for masked arrays -- useful if your data contains
"missing" values
-
+ numpy.result_type : Returns the type that results from applying the
+ NumPy type promotion rules to the arguments.
Examples
--------
>>> data = range(1,5)
@@ -348,7 +351,11 @@ def average(a, axis=None, weights=None, returned=False):
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)
+ >>> print(avg.dtype)
+ complex256
"""
a = np.asanyarray(a)