Created
April 11, 2020 13:52
-
-
Save qzhang0130/703516d62b09a6d6f9d1a90ada6f934c to your computer and use it in GitHub Desktop.
np_dot_vs_operator_*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# Example 1 | |
vec1 = np.array([1, 2]) | |
vec2 = np.array([2, 3]) | |
vec1*vec2 | |
# Return | |
# array([2, 6]) | |
np.dot(vec1, vec2) | |
# Return | |
# 8 | |
# Example 2 | |
vec3 = np.array([[1, 2], [3, 4]]) | |
vec4 = np.array([1, 2]) | |
vec3*vec4 | |
# Return | |
# array([[1, 4], [3, 8]]) | |
np.dot(vec3, vec4) | |
# Return | |
# array([5, 11]) | |
# Example 3 | |
vec5 = np.array([[1, 2, 3], [4, 5, 6]]) | |
vec6 = np.array([1, 2]) | |
vec5.T*vec6 | |
# Return | |
# array([[1, 8], [2, 10], [3, 12]]) | |
np.dot(vec5.T, vec6) | |
# Return | |
# array([9, 12, 15]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment