3 and 4
4
3 and 5 and 8
8
3 and 8 and 5
5
3 or 5 or 8
3
8 or 5 or 3
8
5 > 3 < 4
True
5 > 4
True
not 5 > 4
False
not 3 > 4
True
(not 1) or (0 and 1) or (3 and 4) or (5 and 6) or (7 and 8 and 9)
4
L = [[1,2],[3,4]]
import numpy
A = numpy.array(L)
print(A)
[[1 2]
[3 4]]
type(A)
numpy.ndarray
import numpy as np
L1 = [[1,2,3],[4,5,6],[7,8,9]]
A1 = np.array(L1)
print(A1)
[[1 2 3]
[4 5 6]
[7 8 9]]
d1 = [1,2,3,4,0.1,7]
d2 = (1,2,3,4,2.3)
d3 = [[1,2,3,4],[5,6,7,8]]
d4 = [(1,2,3,4),(5,6,7,8)]
d5 = ((1,2,3,4),(5,6,7,8))
d11 = np.array(d1)
print(d11)
[1. 2. 3. 4. 0.1 7. ]
d21 = np.array(d2)
print(d21)
[1. 2. 3. 4. 2.3]
d31 = np.array(d3)
print(d31)
[[1 2 3 4]
[5 6 7 8]]
z1 = np.ones((3,4))
print(z1)
[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]
z2 = np.zeros((4,3))
print(z2)
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
z3 = np.arange(10)
print(z3)
[0 1 2 3 4 5 6 7 8 9]
z4 = np.arange(2,10)
print(z4)
[2 3 4 5 6 7 8 9]
z5 = np.arange(2,10,2)
print(z5)
[2 4 6 8]
s11 = d11.shape
print(s11)
(6,)
s31 = d31.shape
print(s31)
(2, 4)
z6 = np.ones((5,1))
print(z6)
s61 = z6.shape
print(s61)
[[1.]
[1.]
[1.]
[1.]
[1.]]
(5, 1)
r1 = z3.reshape((2,5))
print(r1)
[[0 1 2 3 4]
[5 6 7 8 9]]
A = np.array([[1,2],[3,4]])
B = np.array([[5,6],[7,8]])
print(A)
[[1 2]
[3 4]]
C1 = A - B
C2 = A + B
C3 = A * B
C4 = A / B
C5 = A / 3
C6 = 1 / A
C7 = A **2
print(C1)
[[-4 -4]
[-4 -4]]
print(C2)
[[ 6 8]
[10 12]]
print(C3)
[[ 5 12]
[21 32]]
print(C4)
[[0.2 0.33333333]
[0.42857143 0.5 ]]
print(C5)
[[0.33333333 0.66666667]
[1. 1.33333333]]
print(C6)
[[1. 0.5 ]
[0.33333333 0.25 ]]
print(C7)
[[ 1 4]
[ 9 16]]
C8 = np.array([1,2,3,3.1,4.5,6,7,8,9])
C9 = (C8 - min(C8))/(max(C8)-min(C8))
print(C9)
[0. 0.125 0.25 0.2625 0.4375 0.625 0.75 0.875 1. ]
D = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])
E1 = np.sqrt(D)
print(E1)
[[1. 1.41421356 1.73205081 2. ]
[2.23606798 2.44948974 2.64575131 2.82842712]
[3. 3.16227766 3.31662479 3.46410162]
[3.60555128 3.74165739 3.87298335 4. ]]
E2 = np.abs([1,1-2,-100])
print(E2)
[ 1 1 100]
E3 = np.cos(D)
print(E3)
[[ 0.54030231 -0.41614684 -0.9899925 -0.65364362]
[ 0.28366219 0.96017029 0.75390225 -0.14550003]
[-0.91113026 -0.83907153 0.0044257 0.84385396]
[ 0.90744678 0.13673722 -0.75968791 -0.95765948]]
E4 = np.exp(D)
print(E4)
[[2.71828183e+00 7.38905610e+00 2.00855369e+01 5.45981500e+01]
[1.48413159e+02 4.03428793e+02 1.09663316e+03 2.98095799e+03]
[8.10308393e+03 2.20264658e+04 5.98741417e+04 1.62754791e+05]
[4.42413392e+05 1.20260428e+06 3.26901737e+06 8.88611052e+06]]
D = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])
D12 = D[1,2]
print(D12)
7
D1 = D[:,[1,3]]
print(D1)
[[ 2 4]
[ 6 8]
[10 12]
[14 16]]
D1 = D[ ,[1,3]]
print(D1)
File "", line 1
D1 = D[ ,[1,3]]
^
SyntaxError: invalid syntax
D2 = D[[1,3], : ]
print(D2)
[[ 5 6 7 8]
[13 14 15 16]]