62 KiB
62 KiB
In [1]:
import numpy as np
n = 10
x = np.random.normal(size=n)
print(x)[ 1.58706198 0.76481088 -0.96520008 0.51539874 -0.47572211 0.25939945 -0.95294024 -0.57405882 0.50879676 -0.24654269]
In [2]:
import numpy as np
x = np.array([1, 2, 3])
print(x)[1 2 3]
In [3]:
import numpy as np
x = np.log(np.array([4, 7, 8]))
print(x)In [3]:
import numpy as np
from math import log
x = np.array([4, 7, 8])
for i in range(0, len(x)):
x[i] = log(x[i])
print(x)[1 1 2]
In [4]:
import numpy as np
x = np.log(np.array([4, 7, 8], dtype = np.float64))
print(x)[1.38629436 1.94591015 2.07944154]
In [6]:
import numpy as np
x = np.log(np.array([4.0, 7.0, 8.0]))
print(x)[1.38629436 1.94591015 2.07944154]
In [7]:
import numpy as np
x = np.log(np.array([4.0, 7.0, 8.0]))
print(x.itemsize)8
In [8]:
import numpy as np
A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
print(A)[[1.38629436 1.94591015 2.07944154] [1.09861229 2.30258509 2.39789527] [1.38629436 1.60943791 1.94591015]]
In [9]:
import numpy as np
A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
# print the first column, row-major order and elements start with 0
print(A[:,0])[1.38629436 1.09861229 1.38629436]
In [10]:
import numpy as np
A = np.log(np.array([ [4.0, 7.0, 8.0], [3.0, 10.0, 11.0], [4.0, 5.0, 7.0] ]))
# print the first column, row-major order and elements start with 0
print(A[1,:])In [11]:
import numpy as np
n = 10
# define a matrix of dimension 10 x 10 and set all elements to zero
A = np.zeros( (n, n) )
print(A)In [12]:
import numpy as np
n = 10
# define a matrix of dimension 10 x 10 and set all elements to one
A = np.ones( (n, n) )
print(A)In [10]:
import numpy as np
n = 10
# define a matrix of dimension 10 x 10 and set all elements to random numbers with x \in [0, 1]
A = np.random.rand(n, n)
print(A)[[0.99024397 0.28524454 0.75456232 0.6550064 0.93201854 0.56581039 0.47847513 0.27901254 0.51378594 0.68826745] [0.43233927 0.01860471 0.92372452 0.30890614 0.38344601 0.20090571 0.12338667 0.07084957 0.7788002 0.79562216] [0.61097059 0.16691862 0.16716973 0.70509317 0.87505375 0.92738706 0.2376364 0.42426184 0.09735878 0.44986118] [0.92524431 0.63151894 0.1084214 0.59540989 0.46577476 0.25323136 0.04973386 0.63401383 0.01679794 0.88824293] [0.16085625 0.80968775 0.43739905 0.97882041 0.30723675 0.56504648 0.00408112 0.29944343 0.80306828 0.44215703] [0.62763433 0.94598205 0.98794118 0.14996739 0.11298091 0.9720534 0.29485533 0.11620947 0.33364639 0.56332618] [0.52004743 0.13305272 0.63853738 0.33156555 0.852337 0.03859022 0.97373658 0.6888437 0.57950466 0.95643912] [0.51374867 0.75209857 0.14369181 0.8645837 0.90636075 0.42655971 0.21612169 0.11759134 0.66593165 0.7620759 ] [0.64828946 0.47170388 0.59232084 0.41304539 0.66603497 0.65922299 0.16512633 0.75843972 0.3711878 0.9978256 ] [0.5688458 0.05335949 0.94272415 0.69708133 0.4154622 0.18146165 0.5999913 0.79835395 0.51029612 0.78327604]]
In [11]:
# Importing various packages
import numpy as np
n = 100
x = np.random.normal(size=n)
print(np.mean(x))
y = 4+3*x+np.random.normal(size=n)
print(np.mean(y))
z = x**3+np.random.normal(size=n)
print(np.mean(z))
W = np.vstack((x, y, z))
Sigma = np.cov(W)
print(Sigma)
Eigvals, Eigvecs = np.linalg.eig(Sigma)
print(Eigvals)0.07046813671425667 4.120226363271705 0.10838902099535201 [[0.73156174 2.08870448 1.27336093] [2.08870448 6.85239532 3.93668364] [1.27336093 3.93668364 4.08030993]] [10.2648711 0.08491122 1.31448467]
Warning:
Output truncated. This notebook contains too many cells to display efficiently.