Skip to content

Commit 7004baf

Browse files
committed
add documentation
1 parent 775b586 commit 7004baf

2 files changed

Lines changed: 70 additions & 6 deletions

File tree

docs/numpy-functions.ipynb

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
"1. [numpy.argmin](#argmin)\n",
239239
"1. [numpy.argsort](#argsort)\n",
240240
"1. [numpy.asarray*](#asarray)\n",
241+
"1. [numpy.bincount](#bincount)\n",
241242
"1. [numpy.bitwise_and](#bitwise_and)\n",
242243
"1. [numpy.bitwise_or](#bitwise_and)\n",
243244
"1. [numpy.bitwise_xor](#bitwise_and)\n",
@@ -612,6 +613,68 @@
612613
"print('a == c: {}'.format(a is c))"
613614
]
614615
},
616+
{
617+
"cell_type": "markdown",
618+
"metadata": {},
619+
"source": [
620+
"## bincount\n",
621+
"\n",
622+
"`numpy`: https://numpy.org/doc/stable/reference/generated/numpy.bincount.htm\n",
623+
"\n",
624+
"This method counts number of occurrences of each value in array of non-negative integers. A method accepts a single positional, and two keyword arguments, `weights`, and `minlength`. The positional arguments is assumed to be a one-dimensional array of unsigned integers that are either 8 or 16 bits wide. For other types, a `TypeError` is raised.\n",
625+
"\n",
626+
"The `weights` keyword argument can be supplied to apply weigths to the counts. In this case, the return value is a `float` array, otherwise, it is a `uint16`. The `weights` are assumed to be a one-dimensional `ndarray`, otherwise, a `TypeError` is raised. \n",
627+
"\n",
628+
"`minlength` can be supplied to give a lower bound to the length of the `ndarray` returned. In this case, the unused slots are filled with zeros."
629+
]
630+
},
631+
{
632+
"cell_type": "code",
633+
"execution_count": 15,
634+
"metadata": {},
635+
"outputs": [
636+
{
637+
"name": "stdout",
638+
"output_type": "stream",
639+
"text": [
640+
"a: array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint8)\n",
641+
"bincount(a): array([1, 1, 1, 1, 1, 1, 1, 1], dtype=uint16)\n",
642+
"\n",
643+
"a: array([0, 0, 1, 1, 1, 2, 2, 2, 2], dtype=uint8)\n",
644+
"bincount(a): array([2, 3, 4], dtype=uint16)\n",
645+
"\n",
646+
"a: array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint8)\n",
647+
"w: array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8], dtype=float64)\n",
648+
"bincount(a, weights=w): array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8], dtype=float64)\n",
649+
"\n",
650+
"a: array([0, 1, 2, 3], dtype=uint8)\n",
651+
"bincount(a, minlength=8): array([1, 1, 1, 1, 0, 0, 0, 0], dtype=uint16)\n",
652+
"\n",
653+
"\n"
654+
]
655+
}
656+
],
657+
"source": [
658+
"%%micropython -unix 1\n",
659+
"\n",
660+
"from ulab import numpy as np\n",
661+
"\n",
662+
"a = np.array(range(8), dtype=np.uint8)\n",
663+
"\n",
664+
"print(f'a: {a}\\nbincount(a): {np.bincount(a)}')\n",
665+
"\n",
666+
"a = np.array([0, 0, 1, 1, 1, 2, 2, 2, 2], dtype=np.uint8)\n",
667+
"print(f'\\na: {a}\\nbincount(a): {np.bincount(a)}')\n",
668+
"\n",
669+
"a = np.array(range(8), dtype=np.uint8)\n",
670+
"w = np.array([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.8])\n",
671+
"\n",
672+
"print(f'\\na: {a}\\nw: {w}\\nbincount(a, weights=w): {np.bincount(a, weights=w)}')\n",
673+
"\n",
674+
"a = np.array(range(4), dtype=np.uint8)\n",
675+
"print(f'\\na: {a}\\nbincount(a, minlength=8): {np.bincount(a, minlength=8)}')\n"
676+
]
677+
},
615678
{
616679
"cell_type": "markdown",
617680
"metadata": {},
@@ -2944,7 +3007,7 @@
29443007
],
29453008
"metadata": {
29463009
"kernelspec": {
2947-
"display_name": "Python 3.8.5 ('base')",
3010+
"display_name": "base",
29483011
"language": "python",
29493012
"name": "python3"
29503013
},
@@ -3006,11 +3069,6 @@
30063069
"_Feature"
30073070
],
30083071
"window_display": false
3009-
},
3010-
"vscode": {
3011-
"interpreter": {
3012-
"hash": "9e4ec6f642f986afcc9e252c165e44859a62defc5c697cae6f82c2943465ec10"
3013-
}
30143072
}
30153073
},
30163074
"nbformat": 4,

docs/ulab-change-log.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Wed, 3 Sep 2025
2+
3+
version 6.9.0
4+
5+
add bincount
6+
17
Fri, 06 Jun 2025
28

39
version 6.8.0

0 commit comments

Comments
 (0)