代码示例
# -*- coding: utf-8 -*- import numpy as np matrix = np.arange(12).reshape(4, -1) print(matrix) """ [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]] """ # 保存二维数组 np.savetxt("matrix.txt", matrix, fmt="%d", delimiter=",") # 读取二维数组 m = np.loadtxt("matrix.txt", dtype=int, delimiter=",") print(m) """ [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]] """
参考