add asarray, size documentation
This commit is contained in:
parent
1fc2f18358
commit
d40672d946
4 changed files with 231 additions and 45 deletions
|
|
@ -27,7 +27,7 @@ copyright = '2019-2022, Zoltán Vörös and contributors'
|
|||
author = 'Zoltán Vörös'
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '4.1.0'
|
||||
release = '4.2.0'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -11,37 +11,39 @@ the firmware was compiled with complex support.
|
|||
3. `numpy.argmax <#argmax>`__
|
||||
4. `numpy.argmin <#argmin>`__
|
||||
5. `numpy.argsort <#argsort>`__
|
||||
6. `numpy.clip <#clip>`__
|
||||
7. `numpy.compress\* <#compress>`__
|
||||
8. `numpy.conjugate\* <#conjugate>`__
|
||||
9. `numpy.convolve\* <#convolve>`__
|
||||
10. `numpy.delete <#delete>`__
|
||||
11. `numpy.diff <#diff>`__
|
||||
12. `numpy.dot <#dot>`__
|
||||
13. `numpy.equal <#equal>`__
|
||||
14. `numpy.flip\* <#flip>`__
|
||||
15. `numpy.imag\* <#imag>`__
|
||||
16. `numpy.interp <#interp>`__
|
||||
17. `numpy.isfinite <#isfinite>`__
|
||||
18. `numpy.isinf <#isinf>`__
|
||||
19. `numpy.max <#max>`__
|
||||
20. `numpy.maximum <#maximum>`__
|
||||
21. `numpy.mean <#mean>`__
|
||||
22. `numpy.median <#median>`__
|
||||
23. `numpy.min <#min>`__
|
||||
24. `numpy.minimum <#minimum>`__
|
||||
25. `numpy.not_equal <#equal>`__
|
||||
26. `numpy.polyfit <#polyfit>`__
|
||||
27. `numpy.polyval <#polyval>`__
|
||||
28. `numpy.real\* <#real>`__
|
||||
29. `numpy.roll <#roll>`__
|
||||
30. `numpy.sort <#sort>`__
|
||||
31. `numpy.sort_complex\* <#sort_complex>`__
|
||||
32. `numpy.std <#std>`__
|
||||
33. `numpy.sum <#sum>`__
|
||||
34. `numpy.trace <#trace>`__
|
||||
35. `numpy.trapz <#trapz>`__
|
||||
36. `numpy.where <#where>`__
|
||||
6. `numpy.asarray <#asarray>`__
|
||||
7. `numpy.clip <#clip>`__
|
||||
8. `numpy.compress\* <#compress>`__
|
||||
9. `numpy.conjugate\* <#conjugate>`__
|
||||
10. `numpy.convolve\* <#convolve>`__
|
||||
11. `numpy.delete <#delete>`__
|
||||
12. `numpy.diff <#diff>`__
|
||||
13. `numpy.dot <#dot>`__
|
||||
14. `numpy.equal <#equal>`__
|
||||
15. `numpy.flip\* <#flip>`__
|
||||
16. `numpy.imag\* <#imag>`__
|
||||
17. `numpy.interp <#interp>`__
|
||||
18. `numpy.isfinite <#isfinite>`__
|
||||
19. `numpy.isinf <#isinf>`__
|
||||
20. `numpy.max <#max>`__
|
||||
21. `numpy.maximum <#maximum>`__
|
||||
22. `numpy.mean <#mean>`__
|
||||
23. `numpy.median <#median>`__
|
||||
24. `numpy.min <#min>`__
|
||||
25. `numpy.minimum <#minimum>`__
|
||||
26. `numpy.not_equal <#equal>`__
|
||||
27. `numpy.polyfit <#polyfit>`__
|
||||
28. `numpy.polyval <#polyval>`__
|
||||
29. `numpy.real\* <#real>`__
|
||||
30. `numpy.roll <#roll>`__
|
||||
31. `numpy.size <#size>`__
|
||||
32. `numpy.sort <#sort>`__
|
||||
33. `numpy.sort_complex\* <#sort_complex>`__
|
||||
34. `numpy.std <#std>`__
|
||||
35. `numpy.sum <#sum>`__
|
||||
36. `numpy.trace <#trace>`__
|
||||
37. `numpy.trapz <#trapz>`__
|
||||
38. `numpy.where <#where>`__
|
||||
|
||||
all
|
||||
---
|
||||
|
|
@ -269,6 +271,53 @@ example:
|
|||
|
||||
|
||||
|
||||
asarray
|
||||
-------
|
||||
|
||||
``numpy``:
|
||||
https://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html
|
||||
|
||||
The function takes a single positional argument, and an optional keyword
|
||||
argument, ``dtype``, with a default value of ``None``.
|
||||
|
||||
If the positional argument is an ``ndarray``, and its ``dtypes`` is
|
||||
identical to the value of the keyword argument, or if the keyword
|
||||
argument is ``None``, then the positional argument is simply returned.
|
||||
If the original ``dtype``, and the value of the keyword argument are
|
||||
different, then a copy is returned, with appropriate ``dtype``
|
||||
conversion.
|
||||
|
||||
If the positional argument is an iterable, then the function is simply
|
||||
an alias for ``array``.
|
||||
|
||||
.. code::
|
||||
|
||||
# code to be run in micropython
|
||||
|
||||
from ulab import numpy as np
|
||||
|
||||
a = np.array(range(9), dtype=np.uint8)
|
||||
b = np.asarray(a)
|
||||
c = np.asarray(a, dtype=np.int8)
|
||||
print('a:{}'.format(a))
|
||||
print('b:{}'.format(b))
|
||||
print('a == b: {}'.format(a is b))
|
||||
|
||||
print('\nc:{}'.format(c))
|
||||
print('a == c: {}'.format(a is c))
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
a:array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=uint8)
|
||||
b:array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=uint8)
|
||||
a == b: True
|
||||
|
||||
c:array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int8)
|
||||
a == c: False
|
||||
|
||||
|
||||
|
||||
|
||||
clip
|
||||
----
|
||||
|
||||
|
|
@ -1381,6 +1430,39 @@ Vertical rolls require two internal copies of single columns.
|
|||
|
||||
|
||||
|
||||
size
|
||||
----
|
||||
|
||||
The function takes a single positional argument, and an optional keyword
|
||||
argument, ``axis``, with a default value of ``None``, and returns the
|
||||
size of an array along that axis. If ``axis`` is ``None``, the total
|
||||
length of the array (the product of the elements of its shape) is
|
||||
returned.
|
||||
|
||||
.. code::
|
||||
|
||||
# code to be run in micropython
|
||||
|
||||
from ulab import numpy as np
|
||||
|
||||
a = np.ones((2, 3))
|
||||
|
||||
print(a)
|
||||
print('size(a, axis=0): ', np.size(a, axis=0))
|
||||
print('size(a, axis=1): ', np.size(a, axis=1))
|
||||
print('size(a, axis=None): ', np.size(a, axis=None))
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
array([[1.0, 1.0, 1.0],
|
||||
[1.0, 1.0, 1.0]], dtype=float64)
|
||||
size(a, axis=0): 2
|
||||
size(a, axis=1): 3
|
||||
size(a, axis=None): 6
|
||||
|
||||
|
||||
|
||||
|
||||
sort
|
||||
----
|
||||
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@
|
|||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-12T16:41:02.299473Z",
|
||||
"start_time": "2022-01-12T16:41:02.282389Z"
|
||||
"end_time": "2022-01-14T19:55:15.200755Z",
|
||||
"start_time": "2022-01-14T19:55:15.193656Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
|
|
@ -52,8 +52,8 @@
|
|||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-12T16:41:02.475299Z",
|
||||
"start_time": "2022-01-12T16:41:02.401569Z"
|
||||
"end_time": "2022-01-14T19:55:17.871864Z",
|
||||
"start_time": "2022-01-14T19:55:17.858935Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
|
|
@ -237,6 +237,7 @@
|
|||
"1. [numpy.argmax](#argmax)\n",
|
||||
"1. [numpy.argmin](#argmin)\n",
|
||||
"1. [numpy.argsort](#argsort)\n",
|
||||
"1. [numpy.asarray](#asarray)\n",
|
||||
"1. [numpy.clip](#clip)\n",
|
||||
"1. [numpy.compress*](#compress)\n",
|
||||
"1. [numpy.conjugate*](#conjugate)\n",
|
||||
|
|
@ -261,6 +262,7 @@
|
|||
"1. [numpy.polyval](#polyval)\n",
|
||||
"1. [numpy.real*](#real)\n",
|
||||
"1. [numpy.roll](#roll)\n",
|
||||
"1. [numpy.size](#size)\n",
|
||||
"1. [numpy.sort](#sort)\n",
|
||||
"1. [numpy.sort_complex*](#sort_complex)\n",
|
||||
"1. [numpy.std](#std)\n",
|
||||
|
|
@ -543,6 +545,62 @@
|
|||
"print('\\nthe original array:\\n', a)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## asarray\n",
|
||||
"\n",
|
||||
"`numpy`: https://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html\n",
|
||||
"\n",
|
||||
"The function takes a single positional argument, and an optional keyword argument, `dtype`, with a default value of `None`. \n",
|
||||
"\n",
|
||||
"If the positional argument is an `ndarray`, and its `dtypes` is identical to the value of the keyword argument, or if the keyword argument is `None`, then the positional argument is simply returned. If the original `dtype`, and the value of the keyword argument are different, then a copy is returned, with appropriate `dtype` conversion. \n",
|
||||
"\n",
|
||||
"If the positional argument is an iterable, then the function is simply an alias for `array`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-14T20:05:22.017031Z",
|
||||
"start_time": "2022-01-14T20:05:22.002463Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"a:array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=uint8)\n",
|
||||
"b:array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=uint8)\n",
|
||||
"a == b: True\n",
|
||||
"\n",
|
||||
"c:array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=int8)\n",
|
||||
"a == c: False\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%micropython -unix 1\n",
|
||||
"\n",
|
||||
"from ulab import numpy as np\n",
|
||||
"\n",
|
||||
"a = np.array(range(9), dtype=np.uint8)\n",
|
||||
"b = np.asarray(a)\n",
|
||||
"c = np.asarray(a, dtype=np.int8)\n",
|
||||
"print('a:{}'.format(a))\n",
|
||||
"print('b:{}'.format(b))\n",
|
||||
"print('a == b: {}'.format(a is b))\n",
|
||||
"\n",
|
||||
"print('\\nc:{}'.format(c))\n",
|
||||
"print('a == c: {}'.format(a is c))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
|
@ -1941,6 +1999,52 @@
|
|||
"print(\"\\na rolled with None:\\n\", a)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## size\n",
|
||||
"\n",
|
||||
"The function takes a single positional argument, and an optional keyword argument, `axis`, with a default value of `None`, and returns the size of an array along that axis. If `axis` is `None`, the total length of the array (the product of the elements of its shape) is returned."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-14T19:58:44.044501Z",
|
||||
"start_time": "2022-01-14T19:58:44.034585Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"array([[1.0, 1.0, 1.0],\n",
|
||||
" [1.0, 1.0, 1.0]], dtype=float64)\n",
|
||||
"size(a, axis=0): 2\n",
|
||||
"size(a, axis=1): 3\n",
|
||||
"size(a, axis=None): 6\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%micropython -unix 1\n",
|
||||
"\n",
|
||||
"from ulab import numpy as np\n",
|
||||
"\n",
|
||||
"a = np.ones((2, 3))\n",
|
||||
"\n",
|
||||
"print(a)\n",
|
||||
"print('size(a, axis=0): ', np.size(a, axis=0))\n",
|
||||
"print('size(a, axis=1): ', np.size(a, axis=1))\n",
|
||||
"print('size(a, axis=None): ', np.size(a, axis=None))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-12T17:00:33.582729Z",
|
||||
"start_time": "2022-01-12T17:00:33.566591Z"
|
||||
"end_time": "2022-01-14T19:54:52.171096Z",
|
||||
"start_time": "2022-01-14T19:54:52.162815Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
"author = 'Zoltán Vörös'\n",
|
||||
"\n",
|
||||
"# The full version, including alpha/beta/rc tags\n",
|
||||
"release = '4.1.0'\n",
|
||||
"release = '4.2.0'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# -- General configuration ---------------------------------------------------\n",
|
||||
|
|
@ -215,11 +215,11 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-12T17:03:49.038101Z",
|
||||
"start_time": "2022-01-12T17:03:48.886617Z"
|
||||
"end_time": "2022-01-14T20:05:37.425494Z",
|
||||
"start_time": "2022-01-14T20:05:35.620545Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
|
|
@ -256,11 +256,11 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2022-01-12T17:03:52.084601Z",
|
||||
"start_time": "2022-01-12T17:03:50.354118Z"
|
||||
"end_time": "2022-01-14T20:06:04.832792Z",
|
||||
"start_time": "2022-01-14T20:06:00.259738Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
|
|
|
|||
Loading…
Reference in a new issue