数据挖掘—Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习

什么是Numpy

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
NumPy系统是Python的一种开源的数值计算扩展。这种工具可用来存储和处理大型矩阵(任意维度的数据处理),比Python自身的嵌套列表(nested list structure)结构要高效的多(该结构也可以用来表示矩阵(matrix))。
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据类型ndarray
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
NumPy provides an N-dimension array type, the ndarray, which describes a collection of ‘items’of the same type.
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
NumPy提供了一个N维数组类型ndarray,它描述了相同类型的”items”的集合。
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> score = np.array([ <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [80, 89, 86, 67, 79], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [78, 97, 89, 67, 81], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [90, 94, 78, 67, 74], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [91, 91, 90, 67, 69], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [76, 87, 75, 67, 86], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [70, 79, 84, 67, 84], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [94, 92, 93, 67, 64], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [86, 85, 83, 67, 80]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(score, type(score)) # <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321201413848-1293929555.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **ndarray与Python原生list运算效率对比** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import random
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import time
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 生成一个大数组
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
python_list = []
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
for i in range(100000000):
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
python_list.append(random.random())
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
ndarray_list = np.array(python_list)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
len(ndarray_list)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 原生pythonlist求和
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
t1 = time.time()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
a = sum(python_list)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
t2 = time.time()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
d1 = t2 – t1
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(d1) # 0.7309620380401611
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# ndarray求和
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
t3 = time.time()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
b = np.sum(ndarray_list)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
t4 = time.time()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
d2 = t4 – t3
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(d2) # 0.12980318069458008
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
Numpy优势:
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
1)存储风格
数据挖掘---Numpy的学习
ndarray – 相同类型 – 通用性不强 – 数据是连续性的存储
数据挖掘---Numpy的学习
list – 不同类型 – 通用性很强 – 引用的方式且不连续的堆空间存储
数据挖掘---Numpy的学习
2)并行化运算
数据挖掘---Numpy的学习
ndarray支持向量化运算
数据挖掘---Numpy的学习
3)底层语言
数据挖掘---Numpy的学习
C语言,解除了GIL
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
1、内存块风格
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
2、ndarry支持并行化运算
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
3、Numpy底层是C编程,内部解除了GIL(全局解释器锁–实际上只有一个线程)的限制
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
认识N维数组的属性-ndarry的属性(shape+dtype)
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
ndarry形状
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>利用元组表示维度(2,3)2个数字代表2维,具体代表2行3列</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> a = np.array([[1, 2, 3], [4, 5, 6]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# (4,)1维用1个数字表示,表示元素个数,为了表示为一个元组,我们会添加一个,
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
b = np.array([1, 2, 3, 4])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>(2,2,3),最外层2个二维数组,2维数组内又嵌套了2个一维数组,一个一维数组又有3个元素</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> c = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 如何理解数组的形状? ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 二维数组实际上是在一维数组内嵌套多个一维数组 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321201425602-1426966550.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 三维数组实际上是在一维数组内嵌套多个二维数组 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321201432182-1698902839.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **ndarry的类型** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 在创建ndarray的时候,如果没有指定类型 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 默认整数 int64 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 默认浮点数 float64 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321201437061-1103479012.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321201438379-1543363570.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) </code></pre> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 创建数组的时候指定类型 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 创建数组的时候指定类型(1)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
t = np.array([1.1, 2.2, 3.3], dtype=np.float32)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 创建数组的时候指定类型(2)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
tt = np.array([1.1, 2.2, 3.3], dtype="float32")
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习

基本操作

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
生成数组的方法
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习

生成数组的方法(4种类型)

数据挖掘---Numpy的学习
1)生成0和1
数据挖掘---Numpy的学习
np.zeros(shape)
数据挖掘---Numpy的学习
np.ones(shape)
数据挖掘---Numpy的学习
2)从现有数组中生成
数据挖掘---Numpy的学习
np.array() np.copy() 深拷贝
数据挖掘---Numpy的学习
np.asarray() 浅拷贝
数据挖掘---Numpy的学习
3)生成固定范围的数组
数据挖掘---Numpy的学习
np.linspace(0, 10, 100)
数据挖掘---Numpy的学习
[0, 10] 等距离
数据挖掘---Numpy的学习
np.arange(a, b, c)
数据挖掘---Numpy的学习
range(a, b, c)
数据挖掘---Numpy的学习
[a, b) c是步长
数据挖掘---Numpy的学习
4)生成随机数组
数据挖掘---Numpy的学习
分布状况 – 直方图
数据挖掘---Numpy的学习
1)均匀分布
数据挖掘---Numpy的学习
每组的可能性相等
数据挖掘---Numpy的学习
2)正态分布
数据挖掘---Numpy的学习
σ 幅度、波动程度、集中程度、稳定性、离散程度
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
1、生成0和1的数组
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>1 生成0和1的数组</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> t = np.zeros(shape=(3, 4), dtype="float32") <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> tt = np.ones(shape=[2, 3], dtype=np.int32) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 2 从现有数组生成 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321201455164-94727790.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 方法一:np.array()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
score = np.array([[80, 89, 86, 67, 79],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[94, 92, 93, 67, 64],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[86, 85, 83, 67, 80]])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 方法二:np.copy()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
ttt = np.copy(score)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 方法三:np.asarray()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
tttt = np.asarray(ttt)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
区别:
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
np.array() np.copy() 深拷贝
数据挖掘---Numpy的学习
np.asarray() 浅拷贝
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
3 生成固定范围的数组
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习

np.linspace(0, 10, 100)

数据挖掘---Numpy的学习
[0, 10] 左闭右闭的等距离输出100个数字
数据挖掘---Numpy的学习
np.arange(a, b, c)
数据挖掘---Numpy的学习
[a, b) 左闭右开的步长为c的数组
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
4 生成随机数组( 分布状况 – 直方图)
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
1)均匀分布
数据挖掘---Numpy的学习
每组的可能性相等
数据挖掘---Numpy的学习
2)正态分布
数据挖掘---Numpy的学习
σ 幅度、波动程度、集中程度、稳定性、离散程度
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
1、均匀分布:出现的概率一样
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import matplotlib.pyplot as plt <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>均匀分布:</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> data1 = np.random.uniform(low=-1, high=1, size=1000000) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>1、创建画布</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> plt.figure(figsize=(8, 6), dpi=100) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>2、绘制直方图</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> plt.hist(data1, 1000) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>3、显示图像</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> plt.show() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322202611292-2011380677.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 2、正太分布 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 方差是在概率论和统计方差衡量随机变量或一组数据时离散程度的度量。概率论中方差用来度量随机变量和其数学期望(即均值)之间的偏离程度。统计中的方差(样本方差)是每个样本值与全体样本值的平均数之差的平方值的平均数。标准差越小,数据越集中。 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322202416916-450523662.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322202418075-2123864106.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322202419275-1760996998.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
demo:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import matplotlib.pyplot as plt <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>正太分布</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> data2 = np.random.normal(loc=1.75, scale=0.1, size=1000000) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>1、创建画布</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> plt.figure(figsize=(20, 8), dpi=80) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>2、绘制直方图</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> plt.hist(data2, 1000) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <h1>3、显示图像</h1> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> plt.show() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322202612538-281533806.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **数组的索引与切片** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321205940283-1031934171.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
demo:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> def slice_index(): <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 一维修改: <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr = np.array([12, 32, 31]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr[0]=2 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 二维修改: <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr2 = np.array([[12, 2], [43, 3]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr2[0, 0] = 22 # 修改[12, 2]为[22, 2] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr2) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 三维修改: <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr3 = np.array( <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [[[1, 2, 3], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [4, 5, 6]], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [[12, 3, 34], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [5, 6, 7]]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ) # 3个[,表示3维数组,内又2个2维数组,1个二维数组有2个1维数组,1个一维数组又3个数字,古(2,2,3) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr3[1, 0, 2] = 22 # 修改[12, 3, 34]为[12, 3, 22] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr3) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr3[1, 1, :2]) # 5,6 # 取出前2个 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> if <strong>name</strong> == '<strong>main</strong>': <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 切片与索引 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> slice_index() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **形状改变** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ndarray.reshape(shape) 返回新的ndarray,原始数据没有改变,且仅仅是改变了形状,未改变行列. ndarry.reshape(-1,2) 自动变形 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ndarray.resize(shape) 没有返回值,对原始的ndarray进行了修改,未改变行列 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ndarray.T 转置 行变成列,列变成行 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
demo:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> def np_change(): <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr3 = np.array( <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [[1, 2, 3], [4, 5, 6]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ) # (2, 3) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 方式一: <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> reshape: 返回一个新的ndarry, 且不改变原ndarry,且仅仅是改变了形状,未改变行列 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [[1 2] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [3 4] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [5 6]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr4 = arr3.reshape((3, 2)) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr3.shape) # (2, 3) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr4.shape) # (3, 2) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 方式二: <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> resize: 没有返回值,对原始的ndarray进行了修改,未改变行列 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [[1 2 3 1 2 3]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr3.resize((1, 6)) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr3) # (1, 6) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 方式三: <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> T: 进行行列的转置,把行数据转换为列,列数据转换为行 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [[1 3 5] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [2 4 6]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr4.T) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> if <strong>name</strong> == '<strong>main</strong>': <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 改变形状 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> np_change() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **类型的修改** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ndarray.astype(type) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ndarray 序列化到本地 --》ndarray.tostring():实现序列化 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321205942934-2041020251.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
def type_change():
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
ndarry的类型修改一: astype(‘float32′)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
arr3 = np.array(
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[[1, 2, 3], [4, 5, 6]]
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
) # (2, 3)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
arr4 = arr3.astype("float32") # int转换为float
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(arr3.dtype) # int32
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(arr4.dtype) # float32
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
ndarry的类型修改二: 利用tostrint()序列化
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
arr5 =arr3.tostring() # 序列化 \x01\x00\x00\x00
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(arr5)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
if __name__ == ‘__main__’:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 类型形状
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
type_change()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数组去重
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
set
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> def type_change(): <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ndarry的去重 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> temp = np.array([[1, 2, 3, 4], [3, 4, 5, 6]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 方法一: unique() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> np.unique(temp) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print('利用unique去重:', temp) # [3 4 5 6]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> temp2 = np.array([[1, 2, 3, 4], [3, 4, 5, 6]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 方法二: set的要求是数组必须是一维的,利用flatten()进行降维 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> set(temp2.flatten()) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print('利用set进行降维后:', temp2) # [3 4 5 6]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> if <strong>name</strong> == '<strong>main</strong>': <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # ndarry的去重 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> type_change() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **小结:** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321205945004-2134669680.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ### ndarray的运算(逻辑运算+统计运算+数组运算) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **1、逻辑运算** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 布尔索引 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 通用判断函数 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.all(布尔值) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 只要有一个False就返回False,只有全是True才返回True ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.any() ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 只要有一个True就返回True,只有全是False才返回False ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.where(三元运算符) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.where(布尔值, True的位置的值, False的位置的值) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) * **布尔索引* ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
def demo():
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
逻辑运算
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
temp = np.array([[1, 2, 3, 4], [3, 4, 5, 6]])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 判断temp里面的元素是否大于5(temp > 5)就标记为True 否则为False:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(temp > 5)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 找到数值大于等于5的数字
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(temp[temp >= 5]) # [5 6]
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 找到数值大于等于5的数字,并统一赋值为100
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
temp[temp >= 5] = 100
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(temp)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
if __name__ == ‘__main__’:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 逻辑运算 — 布尔索引
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
demo()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
* *通用判断函数
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
np.all(布尔值)
数据挖掘---Numpy的学习
只要有一个False就返回False,只有全是True才返回True
数据挖掘---Numpy的学习
np.any()
数据挖掘---Numpy的学习
只要有一个True就返回True,只有全是False才返回False
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> def demo(): <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 通用判断函数 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> temp = np.array([[1, 2, 3, 4], [3, 4, 5, 6]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # np.all(): 只要有一个False就返回False,只有全是True才返回True <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.all(temp > 5)) # False <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.all(temp < 15)) # True <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # np.any(): 只要有一个True就返回True,只有全是False才返回False <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.any(temp > 5)) # True <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> if <strong>name</strong> == '<strong>main</strong>': <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 逻辑运算 -- 通用判断函数 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> demo() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) * **三元运算符* ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.where(布尔值, True的位置的值, False的位置的值) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321215054123-928056550.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
def demo():
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
三元运算符
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
temp = np.array([[1, 2, 3, 4], [3, 4, 5, 6]])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# np.where(): np.where(布尔值, True的位置的值, False的位置的值)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(np.where(temp > 4, 100, -100)) # 如果元素大于4,则置为100,否则置为-100
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[[-100 -100 -100 -100]
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[-100 -100 100 100]]
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
if __name__ == ‘__main__’:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 逻辑运算 — 三元运算符
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
demo()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
配合了逻辑与或非的运算:
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> def demo(): <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 三元运算符: 配合逻辑与或非运算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> temp = np.array([[1, 2, 3, 4], [3, 4, 5, 6]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # np.logical_and(), np.logical_or(), logical_not()进行与或非运算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.logical_and(temp > 2, temp < 4)) # 进行与运算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.logical_or(temp > 2, temp < 3)) # 进行或运算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.where(np.logical_or(temp > 2, temp < 3), 1, 0)) # 配合了or的where三木运算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.where(np.logical_and(temp > 2, temp < 4), 1, 0)) # 配合了and的where三木运算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [[-100 -100 -100 -100] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [-100 -100 100 100]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> if <strong>name</strong> == '<strong>main</strong>': <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 逻辑运算 -- 三元运算符 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> demo() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **2、统计运算** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 统计指标函数 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) min, max, mean, median, var, std ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.函数名,例如,arr.max() ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ndarray.方法名, 例如,ndarray.max(arr, ) # 需要先指定好元组 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 返回最大值、最小值所在位置 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.argmax(temp, axis=) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.argmin(temp, axis=) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) * **统计指标函数:需指定好指标* ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321215059056-1099753567.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321215100975-1069748302.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
def demo():
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
统计运算
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
temp = np.array([[1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8]])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(temp.max(axis=0)) # [5 6 7 8], 按照列比较
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(temp.max(axis=1)) # [4 6 8], 按照行比较
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(np.argmax(temp, axis=1)) # [3 3 3], 返回最大值所在的位置
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(np.argmin(temp, axis=1)) # [0 0 0 ], 返回最小值所在的位置
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
if __name__ == ‘__main__’:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 统计运算
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
demo()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **3、数组间运算** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 1. 数组与数的运算 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 2. 数组与数组的运算 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 3. 广播机制 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 4. 矩阵运算 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 1 什么是矩阵 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 矩阵matrix 二维数组 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 矩阵 & 二维数组 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 两种方法存储矩阵 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 1)ndarray 二维数组 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 矩阵乘法: ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.matmul ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.dot ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 2)matrix数据结构 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 2 矩阵乘法运算 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 形状 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) (m, n) * (n, l) = (m, l) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 运算规则 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) A (2, 3) B(3, 2) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) A * B = (2, 2) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **1、数组与数的运算** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190321220429728-267271202.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
def demo():
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
数组与数的运算
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
temp = np.array([[1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8]])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(temp + 10)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(temp * 10)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
if __name__ == ‘__main__’:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 数组与数的运算
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
demo()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
2、数组与数组的运算(需满足广播机制)
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> def demo(): <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 数组与数组的运算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr1 = np.array([[1, 2, 3, 2, 1, 4], [5, 6, 1, 2, 3, 1]]) # 2行6列 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr2 = np.array([[1, 2, 3, 4], [3, 4, 5, 6]]) # 2行4列 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr3 = np.array([[1, 2, 3, 2, 1, 4], [5, 6, 1, 2, 3, 1]]) # 2行6列 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> arr4 = [2] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # print(arr1 + arr2) could not be broadcast together with shapes (2,6) (2,4) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr1 + arr3) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(arr1 + arr4) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> if <strong>name</strong> == '<strong>main</strong>': <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 数组与数组的运算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> demo() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **矩阵运算** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 1 什么是矩阵 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 矩阵matrix 二维数组 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 矩阵 & 二维数组 --》矩阵肯定是二维数组形式存储计算机,但是不是所有的二维数组都是矩阵。 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 两种方法存储矩阵 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 1)ndarray 二维数组 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 矩阵乘法: ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.matmul ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) np.dot ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 2)matrix数据结构 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 2 矩阵乘法运算 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 形状 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) (m, n) * (n, l) = (m, l) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 运算规则 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) A (2, 3) B(3, 2) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) A * B = (2, 2) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **1、什么是矩阵** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200327436-1522413896.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
def demo():
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
矩阵存储方法
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 方案一:ndarray存储矩阵
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
data = np.array([[80, 86],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[82, 80],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[85, 78],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[90, 90],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[86, 82],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[82, 90],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[78, 80],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[92, 94]])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(type(data)) #
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 方案二: matrix存储矩阵
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
data_mat = np.mat([[80, 86],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[82, 80],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[85, 78],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[90, 90],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[86, 82],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[82, 90],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[78, 80],
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
[92, 94]])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(type(data_mat)) #
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
if __name__ == ‘__main__’:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# ndarray存储矩阵
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
demo()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
2、矩阵乘法
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
形状
数据挖掘---Numpy的学习
(m, n) * (n, l) = (m, l)
数据挖掘---Numpy的学习
运算规则
数据挖掘---Numpy的学习
A (2, 3) B(3, 2)
数据挖掘---Numpy的学习
A * B = (2, 2)
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> def demo(): <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> 矩阵乘法API <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 方案一:np.matmul() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> data = np.array([[80, 86], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [82, 80], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [78, 80], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [92, 94]]) # (4,2) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> weight = np.array([[0.5], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [0.5]]) # (2,1) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.matmul(data, weight)) # (4,1) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 方案二: np.dot() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> data_mat = np.mat([[80, 86], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [82, 80], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [78, 80], <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [92, 94]]) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(np.dot(data_mat, weight)) # (4,1) # 扩展方案: print(data @ weight) # ndarry的直接矩阵计算 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> if <strong>name</strong> == '<strong>main</strong>': <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 矩阵乘法API <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> demo() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ### 合并与分割 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **合并** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200342609-377560092.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200346269-664789036.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200347829-1885390256.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **分割** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200351198-929519711.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ### IO操作和数据处理 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200352955-543796951.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 数据准备:test.csv ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
id,value1,value2,value3
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
1,123,1.4,23
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
2,110,,18
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
3,,2.1,19
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
demo:
数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
java;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true; <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> import numpy as np <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> def demo(): <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 合并 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> data = np.genfromtxt("F:\linear\test.csv", delimiter=",") <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> print(data) # 把字符串和缺失值用nan记录(not a number) <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [[ nan nan nan nan] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [ 1. 123. 1.4 23. ] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [ 2. 110. nan 18. ] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> [ 3. nan 2.1 19. ]] <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> ''' <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <p><img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> if <strong>name</strong> == '<strong>main</strong>': <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> # 合并 <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /> demo() <img alt="数据挖掘---Numpy的学习" src="https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png" /></p> <pre><code>![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) **缺失值的处理** ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 1. 直接删除含有缺失值的样本 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 2. 替换/插补 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) 按列求平均,用平均值进行填补 ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200358645-1531537309.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200401664-1575242531.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ![数据挖掘---Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png) ;auto-links:true;collapse:false;first-line:1;gutter:true;html-script:false;light:false;ruler:false;smart-tabs:true;tab-size:4;toolbar:true;
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
import numpy as np
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
def fill_nan_by_column_mean():
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
处理缺失值 — 均值填补
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
”’
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
t = np.genfromtxt("F:\linear\\test.csv", delimiter=",")
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
for i in range(t.shape[1]): # 按照列求平均,先计算数据的shape,看列的数量
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 计算nan的个数
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
nan_num = np.count_nonzero(t[:, i][t[:, i] != t[:, i]])
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
if nan_num > 0:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
now_col = t[:, i]
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 求和
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
now_col_not_nan = now_col[np.isnan(now_col) == False].sum()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 和/个数
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
now_col_mean = now_col_not_nan / (t.shape[0] – nan_num)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 赋值给now_col
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
now_col[np.isnan(now_col)] = now_col_mean
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 赋值给t,即更新t的当前列
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
t[:, i] = now_col
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
print(t)
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
return t
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
if __name__ == ‘__main__’:
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
# 处理缺失值 — 均值填补
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)
fill_nan_by_column_mean()
![数据挖掘—Numpy的学习](https://johngo-pic.oss-cn-beijing.aliyuncs.com/articles/20220812/519608-20190322200402913-137423312.png)

数据挖掘---Numpy的学习

数据挖掘---Numpy的学习
数据挖掘---Numpy的学习

Original: https://www.cnblogs.com/ftl1012/p/10561952.html
Author: 小a玖拾柒
Title: 数据挖掘—Numpy的学习

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/8906/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部