1 print(x + y) # elementwise addition     [1 2 3] + [4 5 6] = [5  7  9]
2 print(x - y) # elementwise subtraction  [1 2 3] - [4 5 6] = [-3 -3 -3]
[5 7 9]
[-3 -3 -3]

1 print(x * y) # elementwise multiplication  [1 2 3] * [4 5 6] = [4  10  18]
2 print(x / y) # elementwise divison         [1 2 3] / [4 5 6] = [0.25  0.4  0.5]
[ 4 10 18]
[ 0.25  0.4   0.5 ]

1 print(x**2) # elementwise power  [1 2 3] ^2 =  [1 4 9]
[1 4 9]

1 x.dot(y) # dot product  1*4 + 2*5 + 3*6
32

1 z = np.array([y, y**2])
2 print(len(z)) # number of rows of array
2

1 z = np.array([y, y**2])
2 z
array([[ 4,  5,  6],
       [16, 25, 36]])

1 z.shape
(2, 3)

1 z.T
array([[ 4, 16],
       [ 5, 25],
       [ 6, 36]])

1 z.T.shape
(3, 2)

1 z.dtype
dtype('int64')

1 z = z.astype('f')
2 z.dtype
dtype('float32')





posted on 2018-03-05 20:17  郑哲  阅读(117)  评论(0编辑  收藏  举报