|
50 | 50 | }, |
51 | 51 | { |
52 | 52 | "cell_type": "code", |
53 | | - "execution_count": 5, |
| 53 | + "execution_count": 3, |
54 | 54 | "metadata": { |
55 | 55 | "ExecuteTime": { |
56 | 56 | "end_time": "2022-01-07T19:16:37.453883Z", |
|
245 | 245 | "\n", |
246 | 246 | "**WARNING:** Difference to `numpy`: the `out` keyword argument is not implemented.\n", |
247 | 247 | "\n", |
248 | | - "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", |
| 248 | + "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", |
249 | 249 | "\n", |
250 | 250 | "`argmin/argmax` return the position (index) of the minimum/maximum in the sequence." |
251 | 251 | ] |
252 | 252 | }, |
253 | | - { |
254 | | - "cell_type": "code", |
255 | | - "execution_count": 8, |
256 | | - "metadata": { |
257 | | - "ExecuteTime": { |
258 | | - "end_time": "2020-10-17T21:26:22.507996Z", |
259 | | - "start_time": "2020-10-17T21:26:22.492543Z" |
260 | | - } |
261 | | - }, |
262 | | - "outputs": [ |
263 | | - { |
264 | | - "name": "stdout", |
265 | | - "output_type": "stream", |
266 | | - "text": [ |
267 | | - "array([1.0, 2.0, 3.0], dtype=float64)\n", |
268 | | - "array([], dtype=float64)\n", |
269 | | - "[] 0\n", |
270 | | - "array([1.0, 2.0, 3.0], dtype=float64)\n", |
271 | | - "array([], dtype=float64)\n", |
272 | | - "\n", |
273 | | - "\n" |
274 | | - ] |
275 | | - } |
276 | | - ], |
277 | | - "source": [ |
278 | | - "%%micropython -unix 1\n", |
279 | | - "\n", |
280 | | - "from ulab import numpy as np\n", |
281 | | - "\n", |
282 | | - "a = np.array([1, 2, 3])\n", |
283 | | - "print(a)\n", |
284 | | - "print(a[-1:-1:-3])\n", |
285 | | - "try:\n", |
286 | | - " sa = list(a[-1:-1:-3])\n", |
287 | | - " la = len(sa)\n", |
288 | | - "except IndexError as e:\n", |
289 | | - " sa = str(e)\n", |
290 | | - " la = -1\n", |
291 | | - " \n", |
292 | | - "print(sa, la)\n", |
293 | | - "\n", |
294 | | - "a[-1:-1:-3] = np.ones(0)\n", |
295 | | - "print(a)\n", |
296 | | - "\n", |
297 | | - "b = np.ones(0) + 1\n", |
298 | | - "print(b)" |
299 | | - ] |
300 | | - }, |
301 | | - { |
302 | | - "cell_type": "code", |
303 | | - "execution_count": 9, |
304 | | - "metadata": { |
305 | | - "ExecuteTime": { |
306 | | - "end_time": "2020-10-17T21:54:49.123748Z", |
307 | | - "start_time": "2020-10-17T21:54:49.093819Z" |
308 | | - } |
309 | | - }, |
310 | | - "outputs": [ |
311 | | - { |
312 | | - "name": "stdout", |
313 | | - "output_type": "stream", |
314 | | - "text": [ |
315 | | - "array([], dtype=float64)\n", |
316 | | - "\n", |
317 | | - "\n" |
318 | | - ] |
319 | | - } |
320 | | - ], |
321 | | - "source": [ |
322 | | - "%%micropython -unix 1\n", |
323 | | - "\n", |
324 | | - "from ulab import numpy as np\n", |
325 | | - "\n", |
326 | | - "a = np.array([1, 2, 3])\n", |
327 | | - "print(a[0:1:-3])" |
328 | | - ] |
329 | | - }, |
330 | | - { |
331 | | - "cell_type": "code", |
332 | | - "execution_count": 81, |
333 | | - "metadata": { |
334 | | - "ExecuteTime": { |
335 | | - "end_time": "2020-10-17T20:59:58.285134Z", |
336 | | - "start_time": "2020-10-17T20:59:58.263605Z" |
337 | | - } |
338 | | - }, |
339 | | - "outputs": [ |
340 | | - { |
341 | | - "data": { |
342 | | - "text/plain": [ |
343 | | - "(0,)" |
344 | | - ] |
345 | | - }, |
346 | | - "execution_count": 81, |
347 | | - "metadata": {}, |
348 | | - "output_type": "execute_result" |
349 | | - } |
350 | | - ], |
351 | | - "source": [ |
352 | | - "a = np.array([1, 2, 3])\n", |
353 | | - "np.ones(0, dtype=uint8) / np.zeros(0, dtype=uint16)\n", |
354 | | - "np.ones(0).shape" |
355 | | - ] |
356 | | - }, |
357 | 253 | { |
358 | 254 | "cell_type": "code", |
359 | 255 | "execution_count": 10, |
|
400 | 296 | "print('min of b (axis=1):', np.min(b, axis=1))" |
401 | 297 | ] |
402 | 298 | }, |
| 299 | + { |
| 300 | + "cell_type": "code", |
| 301 | + "execution_count": 6, |
| 302 | + "metadata": {}, |
| 303 | + "outputs": [ |
| 304 | + { |
| 305 | + "name": "stdout", |
| 306 | + "output_type": "stream", |
| 307 | + "text": [ |
| 308 | + "a: array([[0.0, 1.0, 2.0, 3.0],\n", |
| 309 | + " [4.0, 5.0, 6.0, 7.0],\n", |
| 310 | + " [8.0, 9.0, 10.0, 11.0]], dtype=float64)\n", |
| 311 | + "\n", |
| 312 | + "min of a (axis=1):\n", |
| 313 | + " array([[0.0],\n", |
| 314 | + " [4.0],\n", |
| 315 | + " [8.0]], dtype=float64)\n", |
| 316 | + "\n", |
| 317 | + "min of a (axis=0):\n", |
| 318 | + " array([[0.0, 1.0, 2.0, 3.0]], dtype=float64)\n", |
| 319 | + "\n", |
| 320 | + "\n" |
| 321 | + ] |
| 322 | + } |
| 323 | + ], |
| 324 | + "source": [ |
| 325 | + "%%micropython -unix 1\n", |
| 326 | + "\n", |
| 327 | + "from ulab import numpy as np\n", |
| 328 | + "\n", |
| 329 | + "a = np.array(range(12)).reshape((3, 4))\n", |
| 330 | + "\n", |
| 331 | + "print('a:', a)\n", |
| 332 | + "print('\\nmin of a (axis=1):\\n', np.min(a, axis=1, keepdims=True))\n", |
| 333 | + "print('\\nmin of a (axis=0):\\n', np.min(a, axis=0, keepdims=True))" |
| 334 | + ] |
| 335 | + }, |
403 | 336 | { |
404 | 337 | "cell_type": "markdown", |
405 | 338 | "metadata": {}, |
|
0 commit comments