-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy patharray_multiply.py
More file actions
42 lines (36 loc) · 1.02 KB
/
Copy patharray_multiply.py
File metadata and controls
42 lines (36 loc) · 1.02 KB
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
35
36
37
38
39
40
41
42
# _*_ coding:utf-8 _*_
"""
This file is some demo about numpy array multiply operator
"""
import numpy as np
def one_dim_arr_multiply():
"""
the difference between * and dot operator about numpy.array()
of one dimension
:return none:
"""
arr1 = np.array([1, 2])
arr2 = np.array([3, 4])
print arr1 * arr2 # -> [3 8]
# for 1 dim array np.dot gets inner product of vector
print np.dot(arr1, arr2.transpose()) # 11
print arr1, arr2.transpose()
print np.dot(arr1, arr2) # 11
def mul_dim_arr_multiply():
"""
the difference between * and dot operator about numpy.array()
of multiple dimension
"""
arr1 = np.array([[1], [2]])
arr2 = np.array([[3], [4]])
print arr1 * arr2
# >> [[3]
# [8]]
print np.dot(arr1, arr2.transpose())
# >>>[[3 4]
# [6 8]]
print np.dot(arr1, arr2)
# ValueError: shapes (2,1) and (2,1) not aligned: 1 (dim 1) != 2 (dim 0)
if __name__ == '__main__':
# one_dim_arr_multiply()
mul_dim_arr_multiply()