Skip to content

Commit 2c1b57e

Browse files
committed
Sequence and numpy
1 parent 94e780e commit 2c1b57e

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,20 @@ class Employee(Person):
635635
self.staff_num = staff_num
636636
```
637637

638+
### Sequence
639+
```python
640+
class <name>:
641+
def __init__(self, seq):
642+
self.seq = seq
643+
def __len__(self):
644+
return len(self.seq)
645+
def __getitem__(self, i):
646+
return self.seq[i]
647+
def __iter__(self):
648+
for el in self.seq:
649+
yield el
650+
```
651+
638652
### Copy
639653
```python
640654
from copy import copy, deepcopy
@@ -1321,7 +1335,7 @@ Table
13211335
# $ pip3 install tabulate
13221336
from csv import reader
13231337
from tabulate import tabulate
1324-
with open(<filename>, newline='') as csv_file:
1338+
with open(<filename>, encoding='utf-8', newline='') as csv_file:
13251339
reader = reader(csv_file, delimiter=';')
13261340
headers = [a.title() for a in next(reader)]
13271341
print(tabulate(reader, headers))
@@ -1544,14 +1558,16 @@ import numpy as np
15441558
```
15451559

15461560
```python
1547-
value = <array>.min([axis])
1548-
index = <array>.argmin([axis])
1561+
first_column = <array>[:, 0] # Or: <array>[..., 0]
1562+
value = <array>.min([axis])
1563+
index = <array>.argmin([axis])
15491564
```
15501565

15511566
```python
1552-
<view> = <array>.reshape(<shape>)
1553-
<view> = np.broadcast_to(<array>, <shape>)
1554-
<array> = <array>[filter_expression]
1567+
<array>.shape = <shape>
1568+
<view> = <array>.reshape(<shape>)
1569+
<view> = np.broadcast_to(<array>, <shape>)
1570+
<el_or_array> = <array>[filter_expression]
15551571
```
15561572

15571573
### Broadcasting

0 commit comments

Comments
 (0)