- 保存为文本文件(CSV格式):
import numpy as np
# 假设你有一个二维张量矩阵
matrix = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# 保存为CSV文件
np.savetxt('matrix.csv', matrix, delimiter=',', fmt='%d')
- 保存为NumPy数组文件(npy格式):
import numpy as np
# 假设你有一个二维张量矩阵
tensor_matrix = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# 保存为npy文件
np.save('tensor_matrix.npy', tensor_matrix)
- 保存为Excel文件:
import pandas as pd
# 假设你有一个二维张量矩阵
tensor_matrix = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
# 创建 DataFrame
df = pd.DataFrame(tensor_matrix)
# 保存为Excel文件
df.to_excel('tensor_matrix.xlsx', index=False)