-
Notifications
You must be signed in to change notification settings - Fork 2
/
NumpyArrays.txt
34 lines (25 loc) · 1.15 KB
/
NumpyArrays.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
myarr = np.array([[1,2,3],[4,5,6]]) -> 2-dims array
->> accessing myarr[:,:] only, not myarr[:,:,:]
x=numpy.array([[[1,2,3],[4,5,6],[7,8,9]],[[1,2,3],[4,5,6],[7,8,9]],[[1,2,3],[4,5,6],[7,8,9]]]) -> 3-dims array
Generate zeros array
-----------------------------------------------------------------------
x = numpy.zeros(<dim_n>,...,<dim_2>,<dim_1>)
-----------------------------------------------------------------------
Generate ones array
-----------------------------------------------------------------------
x = numpy.ones(<dim_n>,...,<dim_2>,<dim_1>)
-----------------------------------------------------------------------
Accessing array
-----------------------------------------------------------------------
Indexing: 0->(n-1)
1-dim:
x[<start>:<stop>:<step>]
n-dim:
x[<dim_n>,...,<dim1>]
=>> x[<start_dim_n>:<stop_dim_n>:<step_dim_n>,...,<start_dim_1>:<stop_dim_1>:<step_dim_1>]
-----------------------------------------------------------------------
Operation on numpy array
-----------------------------------------------------------------------
numpy.linalg.norm()
-----------------------------------------------------------------------