numpy库
一个亿呢
做一个有梦想的人。
展开
-
矩阵点乘与叉乘的操作,python实现
1. 与线性代数中的矩阵乘法定义相同:np.dot()np.dot(A, B):对于二维矩阵,计算真正意义上的矩阵乘积,即A的i行元素与B的j列元素相乘的积的和作为新矩阵的(i, j)元素;对于一维矩阵(即向量),计算两向量的内积。相当于Matlab中的 *,也相当于线性代数中叉乘线性代数举例:Python代码举例import numpy as np# 2D array A: 2 x 3A = np.array([[1, 2, 3], [4, 5, 6]])# 2D array B: 3原创 2022-04-21 20:13:48 · 5630 阅读 · 0 评论 -
numpy库常用操作
import numpyworld_alcohol = numpy.genfromtxt("world_alcohol.txt", delimiter=",",dtype=str)#源地址、分隔符、数据类型print(type(world_alcohol))numbers = numpy.array([1, 2, 3, 4])numbers.dtype#dtype('int32')numbers = numpy.array([1, 2, 3, '4'])numbers.dtype#dtype原创 2022-02-23 18:34:04 · 258 阅读 · 0 评论 -
numpy库深拷贝(copy函数)与浅拷贝(view函数)
用等于号进行的复制不会复制真正的数据,而是让等号两边的对象指向同一块内存区域#Simple assignments make no copy of array objects or of their data.a = np.arange(12)b = a# a and b are two names for the same ndarray objectb is ab.shape = 3,4print(a.shape) #也是3,4 b改a也改,因为a=bprint(id(a))#2222原创 2022-02-23 19:11:58 · 774 阅读 · 0 评论 -
numpy库中能够返回一些元素操作时的索引
返回每行或者每列最大值索引号的函数argmax,类似的还有argsort等import numpy as npdata = np.sin(np.arange(20)).reshape(5,4)print(data)ind = data.argmax(axis=0)#求每列的最大值的索引号[2 0 3 1]inc = data.argmax()#返回的是所有元素最大值的标号14print( ind)print( inc)data_max = data[ind, range(data.shap原创 2022-02-23 20:15:38 · 963 阅读 · 0 评论