上传文件至 /
This commit is contained in:
31
44龙再飞.py
Normal file
31
44龙再飞.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
text = "Hello"
|
||||||
|
print([ord(c) for c in text])
|
||||||
|
print(chr(65))
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
A = np.array([3, 4])
|
||||||
|
B = np.array([1, 2])
|
||||||
|
print(A + B)
|
||||||
|
print(2 * A)
|
||||||
|
print(np.linalg.norm(A))
|
||||||
|
A = np.array([1, 2, 3])
|
||||||
|
B = np.array([4, 5, 6])
|
||||||
|
print(np.dot(A, B))
|
||||||
|
cos = np.dot(A,B)/(np.linalg.norm(A)*np.linalg.norm(B))
|
||||||
|
print(cos)
|
||||||
|
A2 = np.array([1,0])
|
||||||
|
B2 = np.array([0,1])
|
||||||
|
print(np.dot(A2,B2)/(np.linalg.norm(A2)*np.linalg.norm(B2)))
|
||||||
|
from sklearn.feature_extraction.text import CountVectorizer
|
||||||
|
docs = ["Python 是 编程 语言","Java 是 编程 语言","Python Python Python"]
|
||||||
|
vec = CountVectorizer()
|
||||||
|
print(vec.fit_transform(docs).toarray())
|
||||||
|
print(vec.get_feature_names_out())
|
||||||
|
|
||||||
|
from sklearn.feature_extraction.text import TfidfVectorizer
|
||||||
|
docs = ["Python 编程","Java 编程","Python Python"]
|
||||||
|
tfidf = TfidfVectorizer()
|
||||||
|
matrix = tfidf.fit_transform(docs)
|
||||||
|
print("词表:", tfidf.get_feature_names_out())
|
||||||
|
print("矩阵:\n", matrix.toarray())
|
||||||
Reference in New Issue
Block a user