1 basic knowledge

1
2
#select (extract-src-content "jq-active-actions")
import numpy as np

1
2
print("numpy version:", np.__version__)
np.show_config()
 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
numpy version: 1.16.0
blas_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
  NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]

1
2
Z = np.zeros(10)
print("%d bytes" % (Z.size * Z.itemsize))
1
80 bytes
  • Create a null vector of size 10 but the fifth value which is 1

1
2
3
Z = np.zeros(10)
Z[4] = 1
Z
1
array([0., 0., 0., 0., 1., 0., 0., 0., 0., 0.])
  • Create a vector with values ranging from 10 to 49

1
2
Z = np.arange(10, 50)
Z
1
2
3
array([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, 35, 36, 37, 38, 39, 40, 41, 42, 43,
       44, 45, 46, 47, 48, 49])
  • Create a 3x3 matrix with values ranging from 0 to 8

1
2
T = np.arange(9).reshape(3,3)
T
1
2
3
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])