Files
task-3-2-1-Text-Processing-…/0423+2509165015/2.py
2026-04-23 16:02:35 +08:00

10 lines
427 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

sent1 = "猫 抓 老鼠"
sent2 = "老鼠 抓 猫"
vocab_sent = sorted(set(sent1.split() + sent2.split()))
vec1 = [sent1.split().count(word) for word in vocab_sent]
vec2 = [sent2.split().count(word) for word in vocab_sent]
print("句子1向量", vec1)
print("句子2向量", vec2)
print("向量是否相同:", vec1 == vec2)
large_vocab = [f"word_{i}" for i in range(10000)]
print(f"大词表维度:{len(large_vocab)}")