MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_Mean

Function PyArray_Mean

numpy/core/src/multiarray/calculation.c:717–745  ·  view source on GitHub ↗

NUMPY_API * Mean */

Source from the content-addressed store, hash-verified

715 * Mean
716 */
717NPY_NO_EXPORT PyObject *
718PyArray_Mean(PyArrayObject *self, int axis, int rtype, PyArrayObject *out)
719{
720 PyObject *obj1 = NULL, *obj2 = NULL, *ret;
721 PyArrayObject *arr;
722
723 arr = (PyArrayObject *)PyArray_CheckAxis(self, &axis, 0);
724 if (arr == NULL) {
725 return NULL;
726 }
727 obj1 = PyArray_GenericReduceFunction(arr, n_ops.add, axis,
728 rtype, out);
729 obj2 = PyFloat_FromDouble((double)PyArray_DIM(arr,axis));
730 Py_DECREF(arr);
731 if (obj1 == NULL || obj2 == NULL) {
732 Py_XDECREF(obj1);
733 Py_XDECREF(obj2);
734 return NULL;
735 }
736 if (!out) {
737 ret = PyNumber_TrueDivide(obj1, obj2);
738 }
739 else {
740 ret = PyObject_CallFunction(n_ops.divide, "OOO", out, obj2, out);
741 }
742 Py_DECREF(obj1);
743 Py_DECREF(obj2);
744 return ret;
745}
746
747/*NUMPY_API
748 * Any

Callers 1

__New_PyArray_StdFunction · 0.85

Calls 3

PyArray_CheckAxisFunction · 0.85
PyArray_DIMFunction · 0.85

Tested by

no test coverage detected