你可以使用 NumPy 库将 txt 文件转换为 npy 文件。
以下是一个示例:
import numpy as np
# 读取 txt 文件
data = np.loadtxt("input.txt")
# 将数据保存为 npy 文件
np.save("output.npy", data)
在上面的代码中,我们使用 numpy.loadtxt
函数读取 txt 文件,然后使用 numpy.save
函数将数据保存为 npy 文件。
请注意,如果 txt 文件中的数据不是矩阵形式的,则需要按照自己的需求进行数据处理。