data analysis(数组的保存和读取)

'''
以 二进制 保存数组
保存单个数组。保存成的文件格式是.npy。 np.save(路径和文件名,数组)
保存多个数组。保存成的文件格式是.npz。 np.savez()
读取文件。np.load('路径和文件名文件后缀')。

以 文本 保存数组
np.savetxt(路径和文件名后缀,数组,分隔符,数据类型)
np.loadtxt(路径和文件名后缀,分隔符,数据类型)
np.genfromtxt(路径和文件名后缀,分隔符,数据类型)
'''


import numpy as np
arr = np.arange(12).reshape(3,4)
arr2 = np.array([2,3,6,7])
arr3 = np.random.rand(2,3)

# 保存单个数组
# np.save('./020701',arr)

# 保存多个数组
# np.savez('./020702',arr2,arr3)

# 保存成.txt文本文件
# Save an array to a text file.
# np.savetxt('./020703.txt',arr,fmt='%d',delimiter=',')


# 读取
# 读取.npy
# content = np.load('./020701.npy')
# print(content)

# 读取.npz
# content2 = np.load('./020702.npz')
# for c in content2:
#     print(content2[c])

# 读取.txt
# con = np.loadtxt('./020703.txt',delimiter=',',dtype=np.int32)
# print(con)
# con2 = np.genfromtxt('./020703.txt',delimiter=',',dtype=np.int32)
# print(con2)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值