完成作业3_1_3
This commit is contained in:
48
260416_2509165028.py
Normal file
48
260416_2509165028.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
image=np.array([
|
||||||
|
[100,150,200],
|
||||||
|
[80, 120,180],
|
||||||
|
[60, 90, 140]
|
||||||
|
],dtype=np.uint8)
|
||||||
|
print("原图:")
|
||||||
|
print(image)
|
||||||
|
brighter = image-20
|
||||||
|
print("变暗20:",brighter)
|
||||||
|
top_left = image[0:2, 0:2]
|
||||||
|
print("裁剪左上角:",top_left)
|
||||||
|
flipped1 = np.fliplr(image)
|
||||||
|
print("水平翻转:",flipped1)
|
||||||
|
|
||||||
|
img = np.array([
|
||||||
|
[255, 255, 0, 0 ],
|
||||||
|
[255, 255, 0, 0 ],
|
||||||
|
[0, 0, 255, 255],
|
||||||
|
[0, 0, 255, 255]
|
||||||
|
], dtype=np.uint8)
|
||||||
|
flipped2 = np.fliplr(img)
|
||||||
|
print("水平翻转:",flipped2)
|
||||||
|
rotated = np.transpose(img)
|
||||||
|
flipped3 = np.fliplr(img)
|
||||||
|
print("旋转90度:",flipped3)
|
||||||
|
|
||||||
|
feature_map1=np.array([[1,0,1],[0,1,0],[1,0,1]])
|
||||||
|
feature_map2=np.array([[1,1,1],[1,0,0],[1,0,0]])
|
||||||
|
vector1 = feature_map1.flatten()
|
||||||
|
vector2 = feature_map2.flatten()
|
||||||
|
print("vector1:",vector1)
|
||||||
|
print("vector2:",vector2)
|
||||||
|
|
||||||
|
vocab = ["Python", "学习", "数据", "人工智能", "编程"]
|
||||||
|
doc1 = "Python学习编程"
|
||||||
|
doc2 = "Python人工智能数据"
|
||||||
|
def text_to_vector(text, vocab):
|
||||||
|
words = text.split()
|
||||||
|
vector = np.zeros(len(vocab))
|
||||||
|
for i, word in enumerate(vocab):
|
||||||
|
vector[i] = words.count(word)
|
||||||
|
return vector
|
||||||
|
v1 = text_to_vector(doc1, vocab)
|
||||||
|
v2 = text_to_vector(doc2, vocab)
|
||||||
|
print("doc1向量:", v1)
|
||||||
|
print("doc2向量:", v2)
|
||||||
Reference in New Issue
Block a user