Skip to content

Commit 5f28b95

Browse files
authored
Merge pull request #117 from tushushu/wip-better-doc-example
wip better doc and examples
2 parents e7c0449 + 4c8677f commit 5f28b95

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

README.md

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
# ulist
22

33
[![PyPI](https://img.shields.io/pypi/v/ulist)](https://pypi.org/project/ulist/)
4-
![PyPI - Format](https://img.shields.io/pypi/format/ulist)
54
[![License](https://img.shields.io/github/license/tushushu/ulist)](https://github.com/tushushu/ulist/blob/main/LICENSE)
65
[![CI](https://github.com/tushushu/ulist/workflows/CI/badge.svg)](https://github.com/tushushu/ulist/actions/workflows/main.yml)
76
[![doc](https://github.com/tushushu/ulist/workflows/doc/badge.svg)](https://github.com/tushushu/ulist/actions/workflows/sphinx.yml)
87
[![publish](https://github.com/tushushu/ulist/workflows/publish/badge.svg)](https://github.com/tushushu/ulist/actions/workflows/publish.yml)
9-
[![Code Style](https://img.shields.io/badge/code%20style-flake8-blue)](https://github.com/PyCQA/flake8)
8+
[![code style](https://img.shields.io/badge/style-flake8-blue)](https://github.com/PyCQA/flake8)
109
[![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/tushushu/3a76a8f4c0d25c24b840fe66a3cf44c1/raw/metacov.json)](https://github.com/tushushu/ulist/actions/workflows/coverage.yml)
1110

1211

1312
[**Documentation**](https://tushushu.github.io/ulist/) | [**Source Code**](https://github.com/tushushu/ulist)
1413

1514

1615
### What
17-
Ulist is an ultra fast list/array data structures written in Rust with Python bindings.
16+
Ulist is an ultra fast list/array data structure written in Rust with Python bindings. It aims to be the fundamental package for processing and computing 1-D list/array in Python.
17+
It provides:
18+
19+
* an efficient, flexible and expressive 1-D list/array object;
20+
* broadcasting methods;
21+
* a SQL-like and method-chaining programming experience;
1822

1923

2024
### Requirements
@@ -28,44 +32,51 @@ Run `pip install ulist`
2832

2933
### Examples
3034

31-
#### Calculate the average of unique numbers.
35+
#### Count the number of items in bins.
36+
Given an array `arr`, count the number of items in bins [0, 3), [3, 6), [6, 9) and [9, +inf). The `result` is a Python dictionary with bin names as keys and numbers as values.
3237
```Python
33-
import ulist as ul
34-
35-
arr = ul.from_seq([1.0, 2.0, 3.0, 2.0, 4.0, 5.0], dtype="float")
36-
result = arr.unique().mean()
37-
print(result)
38+
>>> import ulist as ul
39+
40+
>>> arr = ul.arange(12)
41+
>>> arr
42+
UltraFastList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
43+
44+
>>> result = arr.case(default=4)\
45+
... .when(lambda x: x < 3, then=1)\
46+
... .when(lambda x: x < 6, then=2)\
47+
... .when(lambda x: x < 9, then=3)\
48+
... .end()\
49+
... .counter()
50+
>>> result
51+
{4: 3, 2: 3, 3: 3, 1: 3}
3852
```
3953

4054

4155
#### Dot product.
56+
Given two 1-D arrays and calculate the dot product result of those arrays.
4257
```Python
43-
import ulist as ul
44-
45-
arr1 = ul.arange(1, 4)
46-
arr2 = ul.arange(1, 4)
47-
result = arr1.mul(arr2).sum()
48-
print(result)
49-
```
58+
>>> import ulist as ul
5059

60+
>>> arr = ul.from_seq(range(1, 4), dtype='float')
61+
>>> arr
62+
UltraFastList([1.0, 2.0, 3.0])
5163

52-
#### Subtract the mean from the list.
53-
```Python
54-
import ulist as ul
55-
56-
arr = ul.from_seq([1, 2, 3, 4, 5], dtype="float")
57-
result = arr.sub_scala(arr.mean()).to_list()
58-
print(result)
64+
>>> result = arr.mul(arr).sum()
65+
>>> result
66+
14.0
5967
```
6068

61-
62-
#### Use operators instead of methods to calculate variance.
69+
#### Rate of adults.
70+
Given the ages of people as `arr`, and suppose the adults are equal or above 18. Clean the data by removing abnormal values and then calculate the rate of adults.
6371
```Python
64-
import ulist as ul
65-
66-
arr = ul.from_seq([1, 2, 3], dtype="float")
67-
result = ((arr - arr.mean()) ** 2).mean()
68-
print(result)
72+
>>> import ulist as ul
73+
74+
>>> arr = ul.from_seq([-1, 10, 15, 20, 30, 50, 70, 80, 100, 200], dtype='int')
75+
>>> result = arr.where(lambda x: (x >= 0) & (x < 120))\
76+
... .apply(lambda x: x >= 18)\
77+
... .mean()
78+
>>> result
79+
0.75
6980
```
7081

7182

0 commit comments

Comments
 (0)