# Install dependencies
import ds_tut
ds_tut.setup()
Note: you may need to restart the kernel to use updated packages.
Builtin Help
It’s very easy to get additional help just from within a notebook.
? / help / ??
- Just append a
?
to an item to see the docstring or call help(item)
- Append
??
to view the source
Indices
a = np.arange(9).reshape(3, 3)
[[0 1 2]
[3 4 5]
[6 7 8]]
array([[6, 7, 8],
[3, 4, 5],
[0, 1, 2]])
[[0 1 2]
[3 4 5]
[0 0 0]]
a.ravel()[::2] = 1
print(a)
[[1 1 1]
[3 1 5]
[1 0 1]]
Broadcasting
a = np.arange(9).reshape(3, 3)
[[ 0 10 20]
[30 40 50]
[60 70 80]]
b = np.array((10, 10, 10))
print(b)
[[10 11 12]
[13 14 15]
[16 17 18]]
[[ 0 10 20]
[30 40 50]
[60 70 80]]
Non Scalar Multiplication
(array([ 30, 120, 210]), array([ 30, 120, 210]))
a @ np.arange(9).reshape(3, 3)
array([[ 15, 18, 21],
[ 42, 54, 66],
[ 69, 90, 111]])
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 4 is different from 3)
Elementwise Comparison
a = np.full((2, 3), fill_value=2)
b = np.full((2, 3), fill_value=2)
array([[ True, True, True],
[ True, True, True]])