ix keepdims for min, max, argmin, argmax (#707)
This commit is contained in:
parent
be15d62632
commit
20f7259a47
6 changed files with 50 additions and 115 deletions
|
|
@ -546,10 +546,6 @@ static mp_obj_t numerical_argmin_argmax_ndarray(ndarray_obj_t *ndarray, mp_obj_t
|
|||
}
|
||||
|
||||
m_del(int32_t, strides, ULAB_MAX_DIMS);
|
||||
|
||||
if(results->len == 1) {
|
||||
return mp_binary_get_val_array(results->dtype, results->array, 0);
|
||||
}
|
||||
return ulab_tools_restore_dims(ndarray, results, keepdims, _shape_strides);
|
||||
}
|
||||
// we should never get to this point
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
#include "user/user.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#define ULAB_VERSION 6.7.2
|
||||
#define ULAB_VERSION 6.7.3
|
||||
#define xstr(s) str(s)
|
||||
#define str(s) #s
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ copyright = '2019-2025, Zoltán Vörös and contributors'
|
|||
author = 'Zoltán Vörös'
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '6.7.2'
|
||||
release = '6.7.3'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
Sun, 26 Jan 2025
|
||||
|
||||
version 6.7.3
|
||||
|
||||
fix keepdims for min, max, argmin, argmax
|
||||
|
||||
Sun, 19 Jan 2025
|
||||
|
||||
version 6.7.2
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@
|
|||
"author = 'Zoltán Vörös'\n",
|
||||
"\n",
|
||||
"# The full version, including alpha/beta/rc tags\n",
|
||||
"release = '6.7.2'\n",
|
||||
"release = '6.7.3'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# -- General configuration ---------------------------------------------------\n",
|
||||
|
|
@ -217,7 +217,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-02-09T06:27:21.647179Z",
|
||||
|
|
@ -258,7 +258,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-02-09T06:27:42.024028Z",
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-07T19:16:37.453883Z",
|
||||
|
|
@ -245,115 +245,11 @@
|
|||
"\n",
|
||||
"**WARNING:** Difference to `numpy`: the `out` keyword argument is not implemented.\n",
|
||||
"\n",
|
||||
"These functions follow the same pattern, and work with generic iterables, and `ndarray`s. `min`, and `max` return the minimum or maximum of a sequence. If the input array is two-dimensional, the `axis` keyword argument can be supplied, in which case the minimum/maximum along the given axis will be returned. If `axis=None` (this is also the default value), the minimum/maximum of the flattened array will be determined.\n",
|
||||
"These functions follow the same pattern, and work with generic iterables, and `ndarray`s. `min`, and `max` return the minimum or maximum of a sequence. If the input array is two-dimensional, the `axis` keyword argument can be supplied, in which case the minimum/maximum along the given axis will be returned. If `axis=None` (this is also the default value), the minimum/maximum of the flattened array will be determined. The functions also accept the `keepdims=True` or `keepdims=False` keyword argument. The latter case is the default, while the former keeps the dimensions (the number of axes) of the supplied array. \n",
|
||||
"\n",
|
||||
"`argmin/argmax` return the position (index) of the minimum/maximum in the sequence."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2020-10-17T21:26:22.507996Z",
|
||||
"start_time": "2020-10-17T21:26:22.492543Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"array([1.0, 2.0, 3.0], dtype=float64)\n",
|
||||
"array([], dtype=float64)\n",
|
||||
"[] 0\n",
|
||||
"array([1.0, 2.0, 3.0], dtype=float64)\n",
|
||||
"array([], dtype=float64)\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%micropython -unix 1\n",
|
||||
"\n",
|
||||
"from ulab import numpy as np\n",
|
||||
"\n",
|
||||
"a = np.array([1, 2, 3])\n",
|
||||
"print(a)\n",
|
||||
"print(a[-1:-1:-3])\n",
|
||||
"try:\n",
|
||||
" sa = list(a[-1:-1:-3])\n",
|
||||
" la = len(sa)\n",
|
||||
"except IndexError as e:\n",
|
||||
" sa = str(e)\n",
|
||||
" la = -1\n",
|
||||
" \n",
|
||||
"print(sa, la)\n",
|
||||
"\n",
|
||||
"a[-1:-1:-3] = np.ones(0)\n",
|
||||
"print(a)\n",
|
||||
"\n",
|
||||
"b = np.ones(0) + 1\n",
|
||||
"print(b)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2020-10-17T21:54:49.123748Z",
|
||||
"start_time": "2020-10-17T21:54:49.093819Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"array([], dtype=float64)\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%micropython -unix 1\n",
|
||||
"\n",
|
||||
"from ulab import numpy as np\n",
|
||||
"\n",
|
||||
"a = np.array([1, 2, 3])\n",
|
||||
"print(a[0:1:-3])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 81,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2020-10-17T20:59:58.285134Z",
|
||||
"start_time": "2020-10-17T20:59:58.263605Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"(0,)"
|
||||
]
|
||||
},
|
||||
"execution_count": 81,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"a = np.array([1, 2, 3])\n",
|
||||
"np.ones(0, dtype=uint8) / np.zeros(0, dtype=uint16)\n",
|
||||
"np.ones(0).shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
|
|
@ -400,6 +296,43 @@
|
|||
"print('min of b (axis=1):', np.min(b, axis=1))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"a: array([[0.0, 1.0, 2.0, 3.0],\n",
|
||||
" [4.0, 5.0, 6.0, 7.0],\n",
|
||||
" [8.0, 9.0, 10.0, 11.0]], dtype=float64)\n",
|
||||
"\n",
|
||||
"min of a (axis=1):\n",
|
||||
" array([[0.0],\n",
|
||||
" [4.0],\n",
|
||||
" [8.0]], dtype=float64)\n",
|
||||
"\n",
|
||||
"min of a (axis=0):\n",
|
||||
" array([[0.0, 1.0, 2.0, 3.0]], dtype=float64)\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%micropython -unix 1\n",
|
||||
"\n",
|
||||
"from ulab import numpy as np\n",
|
||||
"\n",
|
||||
"a = np.array(range(12)).reshape((3, 4))\n",
|
||||
"\n",
|
||||
"print('a:', a)\n",
|
||||
"print('\\nmin of a (axis=1):\\n', np.min(a, axis=1, keepdims=True))\n",
|
||||
"print('\\nmin of a (axis=0):\\n', np.min(a, axis=0, keepdims=True))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
|
|
|||
Loading…
Reference in a new issue