类型修改与数组去重| 学习笔记

简介: 快速学习类型修改与数组去重

开发者学堂课程【Python 科学计算库 NumPy 快速入门类型修改与数组去重学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/605/detail/8820


类型修改与数组去重


内容简介:

一、类型修改

二、数组的去重


一、类型修改

●ndarray.astype(type)

stock_ change. astype (np. int32)

●ndarray.tostring([order]) 或者 ndarray.tobytes([order]) Construct Python bytes containing the raw data bytes in the array.

。转换成 bytes

arr = np.array([[[1, 2, 3],[4, 5, 6]],[[12, 3,34], [5,6, 7]]])

arr. tostring()

拓展:如果遇到

I0Pub 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

取消注释,多增加

## (bytes/sec) Maximum rate at which messages can be sent on iopub before they

#  are limited.

C .NotebookApp. iopub_ data_ rate_ limit = 10000000

但是不建议这样去修改,jupyter 输出太大会 崩溃

(一)ndarray . astype (type )

In[84]:stock_change.astype(“int32”)

Out[84]:array([[ 0,    1,   0,   2,   0,   0,  -1,   0,   1,-1],

[-1, -1, 0, 1, -1, 0, 0, -1, 0,   0] ,

[ 0,   0, 1, 0,  1,2,   0,    0,   0,  0],  

[ 0,   0, -1,  0, 0,   -1,  0,   -1,   0,  0],

[0, -1, -2, -1, 0,  0,   0,    1,   1,  0],

[0,  1,  0, -2, -2, -1,   1,   -2,  1,   1],

[-2,   0,  0, 0,  0,   -1,   0,   0,    1,    0],

[0,   0,   0, 0, -1, -1,  0, 1,    1,   0]],

dtype=int32)  

(二)ndarray 序列化到本地

ndarray. tostring ( )


二、数组的去重

· ndarray.unique

temp = np.array([[l, 2, 3, 4],[3, 4, 5, 6]])

>>> np.unique(temp)

array([1, 2, 3, 4, 5, 6])

例子:

1、In [88]:temp . np.array([[l, 2, 3, 4],[3, 4, 5, 6]])

In [89]:temp

Out(89):array([[l, 2, 3, 4],

           l3, 4, 5, 6J)

In [91]:np· unique( temp)

Out(91):array([l, 2, 3, 4, 5, 6])

2、In [94] :set (temp. flatten()

Out(94):(1,2,3,4,5,6)

相关文章
|
5月前
|
存储 数据可视化 C语言
C 语言数组教程:定义、访问、修改、循环遍历及多维数组解析
数组用于将多个值存储在单个变量中,而不是为每个值声明单独的变量。 要创建数组,请定义数据类型(例如 int)并指定数组名称,后面跟着方括号 []。 要将值插入其中,请使用逗号分隔的列表,并在花括号内使用
1067 0
|
1月前
|
C++
C++(十一)对象数组
本文介绍了C++中对象数组的使用方法及其注意事项。通过示例展示了如何定义和初始化对象数组,并解释了栈对象数组与堆对象数组在初始化时的区别。重点强调了构造器设计时应考虑无参构造器的重要性,以及在需要进一步初始化的情况下采用二段式初始化策略的应用场景。
数组的相关用法
数组的相关用法
38 0
|
5月前
|
前端开发 JavaScript Java
【面试题】 ES6中将非数组转换为数组的三种方法
【面试题】 ES6中将非数组转换为数组的三种方法
|
11月前
ES6系列笔记-数组方法map(映射)
ES6系列笔记-数组方法map(映射)
37 1
|
分布式计算 索引
常见的数组基本用法(二)
常见的数组基本用法
84 0
|
前端开发
前端学习案例15-数组方法filter&undefined和null对比 原
前端学习案例15-数组方法filter&undefined和null对比 原
64 0
前端学习案例15-数组方法filter&undefined和null对比 原
|
前端开发
前端学习案例11-数组遍历方法3-修改this指向
前端学习案例11-数组遍历方法3-修改this指向
74 0
前端学习案例11-数组遍历方法3-修改this指向
|
Web App开发 JavaScript 前端开发
学习Array类型看这一篇就够了(Array类型特点,Array原型方法,浏览器sort底层实现,深浅拷贝)
学习Array类型看这一篇就够了(Array类型特点,Array原型方法,浏览器sort底层实现,深浅拷贝)
127 0