Skip to content

Commit 6598945

Browse files
committed
Numpy
1 parent 8c2f1c2 commit 6598945

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,12 +1705,36 @@ import numpy as np
17051705
```
17061706

17071707
```python
1708-
<el_or_array> = <array>[:,0] # First column.
1709-
<el_or_array> = <array>.sum([<axis>]) # Axis is an index of dimension that gets collapsed.
1710-
<el_or_array> = <array>.argmin([<axis>]) # Returns index/es of smallest elements.
1711-
<el_or_array> = <array>[filter_expression]
1708+
<el_or_array> = <array>.sum([<axis>]) # Axis is an index of dimension that gets collapsed.
1709+
<el_or_array> = <array>.argmin([<axis>]) # Returns index/es of smallest element/s.
17121710
```
17131711

1712+
### Indexing
1713+
#### Basic indexing
1714+
```python
1715+
<el> = <2d_array>[0, 0]
1716+
```
1717+
1718+
#### Basic slicing
1719+
```python
1720+
<1d_view> = <2d_array>[0] # First row.
1721+
<1d_view> = <2d_array>[:, 0] # First column. Also [..., 0].
1722+
<3d_view> = <2d_array>[None,:,:] # Expanded by dimension of size 1.
1723+
```
1724+
1725+
#### Integer array indexing
1726+
**If row and column indexes differ in shape, they are combined with broadcasting.**
1727+
```python
1728+
<1d_array> = <2d_array>[<1d_row_indexes>, <1d_column_indexes>]
1729+
<2d_array> = <2d_array>[<2d_row_indexes>, <2d_column_indexes>]
1730+
```
1731+
1732+
#### Boolean array indexing
1733+
```python
1734+
<2d_bool_array> = <2d_array> > 0
1735+
<1d_array> = <2d_array>[<2d_bool_array>]
1736+
``
1737+
17141738
### Broadcasting
17151739
**Broadcasting is a set of rules by which NumPy functions operate on arrays of different sizes and/or dimensions.**
17161740
```python

0 commit comments

Comments
 (0)