diff options
-rw-r--r-- | doc/release/1.15.0-notes.rst | 11 | ||||
-rw-r--r-- | doc/source/reference/ufuncs.rst | 13 |
2 files changed, 21 insertions, 3 deletions
diff --git a/doc/release/1.15.0-notes.rst b/doc/release/1.15.0-notes.rst index e8465d21c..e3069a99c 100644 --- a/doc/release/1.15.0-notes.rst +++ b/doc/release/1.15.0-notes.rst @@ -359,8 +359,8 @@ Increased performance in ``random.permutation`` for multidimensional arrays ``permutation`` uses the fast path in ``random.shuffle`` for all input array dimensions. Previously the fast path was only used for 1-d arrays. -Generalized ufuncs now accept ``axes`` and ``keepdims`` arguments ------------------------------------------------------------------ +Generalized ufuncs now accept ``axes``, ``axis`` and ``keepdims`` arguments +--------------------------------------------------------------------------- One can control over which axes a generalized ufunc operates by passing in an ``axes`` argument, a list of tuples with indices of particular axes. For instance, for a signature of ``(i,j),(j,k)->(i,k)`` appropriate for matrix @@ -376,12 +376,19 @@ tuples can be omitted. Hence, for a signature of ``(i),(i)->()`` appropriate for an inner product, one could pass in ``axes=[0, 0]`` to indicate that the vectors are stored in the first dimensions of the two inputs arguments. +As a short-cut for generalized ufuncs that are similar to reductions, i.e., +that act on a single, shared core dimension such as the inner product example +above, one can pass an ``axis`` argument. This is equivalent to passing in +``axes`` with identical entries for all arguments with that core dimension +(e.g., for the example above, ``axes=[(axis,), (axis,)]``). + Furthermore, like for reductions, for generalized ufuncs that have inputs that all have the same number of core dimensions and outputs with no core dimension, one can pass in ``keepdims`` to leave a dimension with size 1 in the outputs, thus allowing proper broadcasting against the original inputs. The location of the extra dimension can be controlled with ``axes``. For instance, for the inner-product example, ``keepdims=True, axes=[-2, -2, -2]`` would act on the +inner-product example, ``keepdims=True, axis=-2`` would act on the one-but-last dimension of the input arguments, and leave a size 1 dimension in that place in the output. diff --git a/doc/source/reference/ufuncs.rst b/doc/source/reference/ufuncs.rst index 995542d77..3cc956887 100644 --- a/doc/source/reference/ufuncs.rst +++ b/doc/source/reference/ufuncs.rst @@ -360,6 +360,17 @@ advanced usage and will not typically be used. and for generalized ufuncs for which all outputs are scalars, the output tuples can be omitted. +*axis* + + .. versionadded:: 1.15 + + A single axis over which a generalized ufunc should operate. This is a + short-cut for ufuncs that operate over a single, shared core dimension, + equivalent to passing in ``axes`` with entries of ``(axis,)`` for each + single-core-dimension argument and ``()`` for all others. For instance, + for a signature ``(i),(i)->()``, it is equivalent to passing in + ``axes=[(axis,), (axis,), ()]``. + *keepdims* .. versionadded:: 1.15 @@ -370,7 +381,7 @@ advanced usage and will not typically be used. ufuncs that operate on inputs that all have the same number of core dimensions and with outputs that have no core dimensions , i.e., with signatures like ``(i),(i)->()`` or ``(m,m)->()``. If used, the location of - the dimensions in the output can be controlled with ``axes``. + the dimensions in the output can be controlled with ``axes`` and ``axis``. *casting* |