Numpy中知识点01

本文记录一下Numpy相关知识点:

1.numpy创建数组:

1
2
import numpy as np
x = np.zeros(shape, dtype = np.uint8)

参考资料:

  1. NumPy 创建数组 | 菜鸟教程

2.numpy数组转换为dataframe:
1
2
3
4
5
6
7
8
9
import numpy as np
import pandas as pd

my_array = np.array([[11,22,33],[44,55,66]])

df = pd.DataFrame(my_array, columns = ['Column_A','Column_B','Column_C'])

print(df)
print(type(df))
> 参考资料: > 1. [How to Convert NumPy Array to Pandas DataFrame – Data to Fish](https://datatofish.com/numpy-array-to-pandas-dataframe/)
3.numpy矩阵乘法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
>>> import numpy as np
>>> a = np.array([[1,1],[1,1]])
>>> a
array([[1, 1],
[1, 1]])
>>> b = np.array([[1,2],[3,4]])
>>> b
array([[1, 2],
[3, 4]])
>>> np.multiply(a,b)
array([[1, 2],
[3, 4]])
>>> np.dot(a,b)
array([[4, 6],
[4, 6]])
>参考资料: >1. [NumPy矩阵乘法](http://c.biancheng.net/numpy/matrix-multiplication.html)