>

LoeiJe

:D 获取中...

何以解忧?唯有暴富

numpy学习笔记

numpy学习笔记

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 2019-10-25 不更新时间了
# numpy 学习笔记
# icenaive
# 参考: https://github.com/lijin-THU/notes-python
# 仅供个人学习使用
#
# 9. 数组与字符串的转换

import numpy as np

a = np.array([[1, 2],
[3, 4]],
dtype = np.uint8)

# 转化为字符串
print(a.tostring())
print(a)

# 可以使用不同的顺序转换
print(a.tostring(order = 'F'))
# 使用Fortran的格式 按照列来读数据

# fromstring 函数从字符串中读出数据 需要指定类型
s = a.tostring()
a = np.fromstring(s, dtype = np.uint8)
print(a)
# 返回数组为1维
a.shape = 2, 2
print(a)

# 对于文本文件 推荐使用
## loadtxt
## genfromtxt
## savetxt
# 对于二进制文本文件 推荐使用
## save
## load
## savez