Skip to content

Commit

Permalink
fixed a couple of small issues in the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
v923z committed Oct 19, 2019
1 parent 8558804 commit 0455d70
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 29 deletions.
76 changes: 65 additions & 11 deletions docs/manual/source/ulab-manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,28 @@ Array initialisation functions

`eye <#eye>`__

`ones <#ones>`__
`ones <#ones,-zeros>`__

`zeros <#zeros>`__
`zeros <#ones,-zeros>`__

`linspace <#linspace>`__

Statistical properties of arrays
--------------------------------

`min <#argmin,-argmax>`__
`min <#min,-argmin,-max,-argmax>`__

`argmin <#argmin,-argmax>`__
`argmin <#min,-argmin,-max,-argmax>`__

`max <#argmin,-argmax>`__
`max <#min,-argmin,-max,-argmax>`__

`argmax <#argmin,-argmax>`__
`argmax <#min,-argmin,-max,-argmax>`__

`sum <#sum>`__
`sum <#sum,-std,-mean>`__

`std <#std>`__
`std <#sum,-std,-mean>`__

`mean <#mean>`__
`mean <#sum,-std,-mean>`__

Manipulation of polynomials
---------------------------
Expand All @@ -210,9 +210,9 @@ FFT routines

`fft\*\* <#fft>`__

`ifft\*\* <#fft>`__
`ifft\*\* <#ifft>`__

`spectrum\*\* <#fft>`__
`spectrum\*\* <#spectrum>`__

ndarray, the basic container
============================
Expand Down Expand Up @@ -1389,6 +1389,51 @@ the sequence.
sum, std, mean
--------------

numpy:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html

numpy:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html

numpy:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.mean.html

These three functions follow the same pattern: if the axis keyword is
not specified, it assumes the default value of ``None``, and returns the
result of the computation for the flattened array. Otherwise, the
calculation is along the given axis.

.. code::
# code to be run in micropython
import ulab as np
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print('a: \n', a)
print('sum, flat array: ', np.sum(a))
print('mean, horizontal: ', np.mean(a, axis=1))
print('std, vertical: ', np.std(a, axis=0))
.. parsed-literal::
a:
array([[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0]], dtype=float)
sum, flat array: 45.0
mean, horizontal: array([2.0, 5.0, 8.0], dtype=float)
std, vertical: array([2.449489831924438, 2.449489831924438, 2.449489831924438], dtype=float)
roll
----

Expand Down Expand Up @@ -2056,6 +2101,9 @@ Fourier transforms
numpy:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.fft.ifft.html

fft
---

Since ulab’s ``ndarray`` does not support complex numbers, the
invocation of the Fourier transform differs from that in ``numpy``. In
``numpy``, you can simply pass an array or iterable to the function, and
Expand Down Expand Up @@ -2114,6 +2162,9 @@ parts of the transform separately.
ifft
----

The above-mentioned rules apply to the inverse Fourier transform. The
inverse is also normalised by ``N``, the number of elements, as is
customary in ``numpy``. With the normalisation, we can ascertain that
Expand Down Expand Up @@ -2152,6 +2203,9 @@ Note that unlike in ``numpy``, the length of the array on which the
Fourier transform is carried out must be a power of 2. If this is not
the case, the function raises a ``ValueError`` exception.

spectrum
--------

In addition to the Fourier transform and its inverse, ``ulab`` also
sports a function called ``spectrum``, which returns the absolute value
of the Fourier transform. This could be used to find the dominant
Expand Down
98 changes: 80 additions & 18 deletions docs/ulab-manual.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
},
{
"cell_type": "code",
"execution_count": 500,
"execution_count": 508,
"metadata": {
"ExecuteTime": {
"end_time": "2019-10-19T13:29:25.408008Z",
"start_time": "2019-10-19T13:29:22.612237Z"
"end_time": "2019-10-19T13:52:48.678946Z",
"start_time": "2019-10-19T13:52:45.769347Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -69,11 +69,11 @@
},
{
"cell_type": "code",
"execution_count": 434,
"execution_count": 502,
"metadata": {
"ExecuteTime": {
"end_time": "2019-10-19T11:53:59.960267Z",
"start_time": "2019-10-19T11:53:59.954615Z"
"end_time": "2019-10-19T13:38:27.980040Z",
"start_time": "2019-10-19T13:38:27.972434Z"
}
},
"outputs": [
Expand Down Expand Up @@ -102,7 +102,7 @@
"{%- if cell.source.split('\\n')[0].startswith('%%micropython') -%}\n",
".. code::\n",
" \n",
"{{ '\\n>>> '.join(['>>> # code to be run in micropython'] + cell.source.strip().split('\\n')[1:]) | indent}}\n",
"{{ '\\n'.join(['# code to be run in micropython'] + cell.source.strip().split('\\n')[1:]) | indent}}\n",
"\n",
"{%- else -%}\n",
".. code::\n",
Expand Down Expand Up @@ -524,27 +524,27 @@
"\n",
"[eye](#eye)\n",
"\n",
"[ones](#ones)\n",
"[ones](#ones,-zeros)\n",
"\n",
"[zeros](#zeros)\n",
"[zeros](#ones,-zeros)\n",
"\n",
"[linspace](#linspace)\n",
"\n",
"## Statistical properties of arrays\n",
"\n",
"[min](#argmin,-argmax)\n",
"[min](#min,-argmin,-max,-argmax)\n",
"\n",
"[argmin](#argmin,-argmax)\n",
"[argmin](#min,-argmin,-max,-argmax)\n",
"\n",
"[max](#argmin,-argmax)\n",
"[max](#min,-argmin,-max,-argmax)\n",
"\n",
"[argmax](#argmin,-argmax)\n",
"[argmax](#min,-argmin,-max,-argmax)\n",
"\n",
"[sum](#sum)\n",
"[sum](#sum,-std,-mean)\n",
"\n",
"[std](#std)\n",
"[std](#sum,-std,-mean)\n",
"\n",
"[mean](#mean)\n",
"[mean](#sum,-std,-mean)\n",
"\n",
"## Manipulation of polynomials\n",
"\n",
Expand All @@ -556,9 +556,9 @@
"\n",
"[fft<sup>**</sup>](#fft)\n",
"\n",
"[ifft<sup>**</sup>](#fft)\n",
"[ifft<sup>**</sup>](#ifft)\n",
"\n",
"[spectrum<sup>**</sup>](#fft)"
"[spectrum<sup>**</sup>](#spectrum)"
]
},
{
Expand Down Expand Up @@ -2148,6 +2148,62 @@
"print('min of b (axis=1):', np.min(b, axis=1))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## sum, std, mean\n",
"\n",
"numpy: https://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html\n",
"\n",
"numpy: https://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html\n",
"\n",
"numpy: https://docs.scipy.org/doc/numpy/reference/generated/numpy.mean.html\n",
"\n",
"These three functions follow the same pattern: if the axis keyword is not specified, it assumes the default value of `None`, and returns the result of the computation for the flattened array. Otherwise, the calculation is along the given axis."
]
},
{
"cell_type": "code",
"execution_count": 506,
"metadata": {
"ExecuteTime": {
"end_time": "2019-10-19T13:48:57.224778Z",
"start_time": "2019-10-19T13:48:57.206804Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a: \n",
" array([[1.0, 2.0, 3.0],\n",
"\t [4.0, 5.0, 6.0],\n",
"\t [7.0, 8.0, 9.0]], dtype=float)\n",
"sum, flat array: 45.0\n",
"mean, horizontal: array([2.0, 5.0, 8.0], dtype=float)\n",
"std, vertical: array([2.449489831924438, 2.449489831924438, 2.449489831924438], dtype=float)\n",
"\n",
"\n"
]
}
],
"source": [
"%%micropython -unix 1\n",
"\n",
"import ulab as np\n",
"\n",
"a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n",
"print('a: \\n', a)\n",
"\n",
"print('sum, flat array: ', np.sum(a))\n",
"\n",
"print('mean, horizontal: ', np.mean(a, axis=1))\n",
"\n",
"print('std, vertical: ', np.std(a, axis=0))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -3061,6 +3117,8 @@
"\n",
"numpy: https://docs.scipy.org/doc/numpy/reference/generated/numpy.fft.ifft.html\n",
"\n",
"## fft\n",
"\n",
"Since ulab's `ndarray` does not support complex numbers, the invocation of the Fourier transform differs from that in `numpy`. In `numpy`, you can simply pass an array or iterable to the function, and it will be treated as a complex array:"
]
},
Expand Down Expand Up @@ -3146,6 +3204,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## ifft\n",
"\n",
"The above-mentioned rules apply to the inverse Fourier transform. The inverse is also normalised by `N`, the number of elements, as is customary in `numpy`. With the normalisation, we can ascertain that the inverse of the transform is equal to the original array."
]
},
Expand Down Expand Up @@ -3202,6 +3262,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## spectrum\n",
"\n",
"In addition to the Fourier transform and its inverse, `ulab` also sports a function called `spectrum`, which returns the absolute value of the Fourier transform. This could be used to find the dominant spectral component in a time series. The arguments are treated in the same way as in `fft`, and `ifft`."
]
},
Expand Down

0 comments on commit 0455d70

Please sign in to comment.