Browse Source

Sequence and numpy

pull/10/head
Jure Šorn 6 years ago
parent
commit
2c1b57e497
1 changed files with 22 additions and 6 deletions
  1. 28
      README.md

28
README.md

@ -635,6 +635,20 @@ class Employee(Person):
self.staff_num = staff_num self.staff_num = staff_num
``` ```
### Sequence
```python
class <name>:
def __init__(self, seq):
self.seq = seq
def __len__(self):
return len(self.seq)
def __getitem__(self, i):
return self.seq[i]
def __iter__(self):
for el in self.seq:
yield el
```
### Copy ### Copy
```python ```python
from copy import copy, deepcopy from copy import copy, deepcopy
@ -1321,7 +1335,7 @@ Table
# $ pip3 install tabulate # $ pip3 install tabulate
from csv import reader from csv import reader
from tabulate import tabulate from tabulate import tabulate
with open(<filename>, newline='') as csv_file: with open(<filename>, encoding='utf-8', newline='') as csv_file:
reader = reader(csv_file, delimiter=';') reader = reader(csv_file, delimiter=';')
headers = [a.title() for a in next(reader)] headers = [a.title() for a in next(reader)]
print(tabulate(reader, headers)) print(tabulate(reader, headers))
@ -1544,14 +1558,16 @@ import numpy as np
``` ```
```python ```python
value = <array>.min([axis]) first_column = <array>[:, 0] # Or: <array>[..., 0]
index = <array>.argmin([axis]) value = <array>.min([axis])
index = <array>.argmin([axis])
``` ```
```python ```python
<view> = <array>.reshape(<shape>) <array>.shape = <shape>
<view> = np.broadcast_to(<array>, <shape>) <view> = <array>.reshape(<shape>)
<array> = <array>[filter_expression] <view> = np.broadcast_to(<array>, <shape>)
<el_or_array> = <array>[filter_expression]
``` ```
### Broadcasting ### Broadcasting

|||||||
100:0
Loading…
Cancel
Save