一、ndarray.astype(type)
返回修改了类型之后的数组
stock_change.astype(np.int32)
二、ndarray.tostring([order])或者ndarray.tobytes([order])
构造包含数组中原始数据字节的Python字节
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[12, 3, 34], [5, 6, 7]]])
arr.tostring()
jupyter输出太大可能导致崩溃问题
如果遇到
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.
这个问题是在jupyer当中对输出的字节数有限制,需要去修改配置文件
创建配置文件
jupyter notebook --generate-config
vi ~/.jupyter/jupyter_notebook_config.py
取消注释,多增加
c.NotebookApp.iopub_data_rate_limit = 10000000
但是不建议这样去修改,jupyter输出太大会崩溃
案例
import numpy as np
ar1 = np.arange(10, dtype=float)
print('ar1 = {0}, ar1.dtype = {1}'.format(ar1, ar1.dtype))
print('-' * 100)
ar2 = ar1.astype(np.int32)
print('ar2 = {0}, ar2.dtype = {1}'.format(ar2, ar2.dtype))
打印结果:
ar1 = [0. 1. 2. 3. 4. 5. 6. 7. 8. 9.], ar1.dtype = float64
----------------------------------------------------------------------------------------------------
ar2 = [0 1 2 3 4 5 6 7 8 9], ar2.dtype = int32
Process finished with exit code 0
|