1.Numpy:
(1)官网
https://numpy.org/
(1) what is numpy?
The fundamental package for scientific computing with Python
(2)multidimensional array object 【编程模型】
1.arrays and matrices [数组和矩阵]
2.可以用来 数组操作、矩阵操作、线下代数、sort、random
2.体验:
求多元一次方程:
3x +y -2z = 5
x-y+4z = -2
2x +3z = 2.5
[0.5 4.5 0.5]
# 把等式系数 抽象成 向量组
3.python list vs numpy arr
python list:放不同数据类型的 元素
numpy arr: 元素类型 必须统一
建议使用 numpy arr 比python list 效率高 【 numpy arr 底层代码使用 c 实现的】
4.如何创建 ndarray
There are 6 general mechanisms for creating arrays:
(1)Conversion from other Python structures (i.e. lists and tuples)
(2)Intrinsic NumPy array creation functions (e.g. arange, ones, zeros, etc.)
(3)Replicating, joining, or mutating existing arrays
(4)Reading arrays from disk, either from standard or custom formats
(5)Creating arrays from raw bytes through the use of strings or buffers
(6)Use of special library functions (e.g., random)
NumPy arrays:
(1)ndarray n N维数组对象
(2)【元素数据类型必须相同】
创建一维数组:
(1)数据类型转化
(2)内置函数
创建二维数组:
(1)数据类型转化
(2)内置函数
5.数组属性:
(1)修改 sharp
(2)转换数据类型:
1.nparr =》 python
2.nparr元素 int =》 float
6.数组拼接与切片:
7.数组的轴 (axis)
(1)numpy 轴 可以理解为方向
(2)数组 0 1 2 表示
eg :
一维数组:只有一个 0 轴
二维数组:0轴 1轴
三维数组:0轴 1轴 2轴
(3)轴 用于计算:(二维、三维)
按照 0、1、2轴进行计算
8.数组的计算:(和矩阵差不多)
1.数组与数的计算
2.形状相同的数组计算
3.不同形状的数组 计算?
4.行数 或 列数相同的 一维数组 与 多维数组 进行计算
np.xxx() api
np.sum
np.mean...
9.数组中的空值
10.数组的操作:
11.random