Professional Documents
Culture Documents
• The elements in a NumPy array are all required to be of the same data
type, and thus will be the same size in memory. The exception: one can
have arrays of (Python, including NumPy) objects, thereby allowing for
arrays of different sized elements.
Result: [3,10,14]
np.power
• Np.power(x,y)
• X: The numbers in the first array serve as the bases.
• Y: The numbers in the second array serve as the exponents.
Example
np.power([1,3,9],2) → [1 9 36]
np.power([1,3,6],[2,7,8]) → [1 2187 1679616]
Practice 2
• Array A: [4,6,7,8,2,6,1,9,1]
• Array B: [7,9,0,1,5,7,3,5,1]
Get the results:
– Array A + Array B
– Array A - Array B
– Array A × Array B
– Array A ÷ Array B
– The cube of array A
– The cube of array B
– The square root of Array A × Array B
– The square root of Array A + Array B
Euclidean
Euclidean
B
��
A
��
�� ��
�ℎ� �������� ������� � ��� � = �� − �� 2 + �� − �� 2
Calculate Euclidean with Python
import numpy as np
B(5,5)
def eucliDist(A,B): ��
�ℎ� �������� ������� � ��� � = �� − �� 2 + �� − �� 2
Practice 3
• Calculate the Euclidean of the following points.
– One-dimensional Point: A(1) and B(8)
– Two-dimensional Point: A(2,3) and B(3,9)
– Three-dimensional Point: A(1,5,6) and B(2,3,7)
– Six-dimensional Point: A(3, 9, 7, 2, 4, 5) and B(-5, -3, -9, 0, 6, 2)
Recommendation System
How does recommendation system work?
• https://www.bilibili.com/video/BV1TS4y197yi?spm_id_from=333.9
99.0.0
1. Import packages
2. Read the files
Use the user ID to create the user if there is no user ID in the dictionary.
Add the user ID to the key dictionary if there is user ID.
4. Calculate Euclidean between two users
The smaller the Euclidean, the more similar these two users are.
5. Calculate the similarity between two users
6. Create a console
Ask people to enter the user ID to the console.
If the user is not in the original dataset, the console will report
an error and ask people to re-enter.