numpy基本运算

class iinfo(object):
def init(self, int_type):
pass
def min(self):
pass
def max(self):
pass
这个代码是不是定义了一个对象,self为形参,int表示整型数据,并且定义了最大最小值范围?
a = np.array([0, 1, 2, 3, 4])
b = np.array((0, 1, 2, 3, 4))
这两个输出的结果均是:
[0 1 2 3 4] <class ‘numpy.ndarray’>
[0 1 2 3 4] <class ‘numpy.ndarray’>
括号不同为什么不是表示别的意思?
创建二维数组,三个括号,创建三维数组,四个括号,依此类推。。。
array() 和asarray() 都可以将结构数据转化为 ndarray,array() 和asarray() 主要区别就是当数据源是ndarray 时, array() 仍然会 copy 出一个副本,占用新的内存,但不改变 dtype 时 asarray() 不会。
def fromfunction(function, 1 shape, **kwargs):表示定义一个函数,这个地方应该比较重要。
零数组、1数组、空数组、单位数组、对角数组、常数数组等都是基本的操作,经常在运算中要用。arange() 函数,linspace() 函数,logspace() 函数,numpy.random.rand() 返回一个由[0,1)内的随机数组成的数组。
利用字典来定义结构:
personType = np.dtype({
‘names’: [‘name’, 'age‘],
‘formats’: [‘U30’, ‘i8’]})
利用包含多个元组的列表来定义结构:
personType = np.dtype([(‘name’, ‘U30’), (‘age’, ‘i8’), (‘weight’, ‘f8’)])
a = np.array([(‘Liming’, 24, 63.9), (‘Mike’, 15, 67.), (‘Jan’, 34, 45.8)],dtype=personType)
数组的属性
numpy.ndarray.ndim返回数组的维数,numpy.ndarray.shape 表示数组的维度,numpy.ndarray.size 数组中所有元素的总量,numpy.ndarray.dtype ndarray 对象的元素类型,numpy.ndarray.itemsize 以字节的形式返回数组中每一个元素的大小。

猜你喜欢

转载自blog.csdn.net/m0_49978528/article/details/109250173