NumPy是什么?能吃吗?好吃吗?
。。。吃货总是把问题想的这么简单。。。
来看看NumPy在官网上是怎么定义自己的吧。。
NumPy is the fundamental package for scientific computing with Python. It contains among other things:
1.a powerful N-dimensional array object
2.sophisticated (broadcasting) functions
3.tools for integrating C/C++ and Fortran code
4.useful linear algebra, Fourier transform, and random number capabilities
Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.
看到了把,翻译成中文就是在数据处理方面屌得很。。
下面来看看具体的基本操作吧:
1.导入NumpPy这个库(安装的话,在之前的blog中已经介绍过啦),并将其简写方便使用:
import numpy as np
array00 = np.array([[1,2,3],[4,5,6]])
print(array00)
3.查看矩阵的维数,矩阵的形式,矩阵中元素的个数
print 'number of dim:',array00.ndim
print 'shape:',array00.shape
print 'size',array00.size
4.设置输出类型
array01 = np.array([1,2,3],dtype=np.int)
print(array01.dtype)