您当前的位置: 首页 >  彭世瑜 Python

Python编程:ndarray数组的保存与读取

彭世瑜 发布时间:2019-02-19 09:55:54 ,浏览量:2

代码示例
# -*- 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]]
"""

参考 python如何保存矩阵,保存matrix,保存numpy.ndarray

关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 2浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.1113s