numpy.MaskedArray.average() is used to return the weighted average of an array along a given axis.
numpy.ma.average (arr, axis = None, weights = None, returned = False)
arr: [array_like] Input masked array whose data to be averaged. Masked entries are not taken into account in the computation.
axis: [int, optional] Axis along which to average arr. If None, averaging is done over the flattened array.
weights: [array_like, optional] The importance that each element has in the computation of the average. If weights = None, then all data in arr are assumed to have a weight equal to one. If weights is complex, the imaginary parts are ignored.
returned: [bool, optional] It indicates whether a tuple (result, sum of weights) should be returned as output (True), or just the result (False). Default is False.
Return: [scalar or MaskedArray] 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.
Code # 1: p>
Input array: [[1 2] [3 -1] [5 -3] ] Masked array: [[- 2] [- -1] [5 -3]] normal average of masked array: 0.75
Code # 2: strong >
Output: p >
Input array: [[1 2] [3 -1] [5 -3]] Masked array: [[- 2] [- -1] [5 -3]] weighted average of masked array: 1.7142857142857142
As information protection continues to be a growing concern for businesses today, IT security certifications have become highly desirable, even as the number of certifications has grown. Now you can s...
Become a master in Python by learning coding best practices and advanced programming concepts in Python 3.7. This book is written for Python developers who wish to go further in mastering Python. A...
If you can program, you are ready to grapple with Bayesian statistics. In this book, you'll learn how to solve statistical problems using Python code instead of math formulas, using discrete probabili...
Computer languages have so far been of the ‘interpreted’ or the ‘compiled’ type. Compiled languages (like ‘C’) have been more common. You prepare a program, save it (the debugged version),...