Numpy学习笔记(一)
来源:互联网 发布:天猫数据直播间 编辑:程序博客网 时间:2024/06/01 08:02
Numpy学习笔记(一)
NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In NumPy dimensions are called axes(轴). The number of axes is rank(秩).
(1)For example, the coordinates of a point in 3D space [1, 2, 1] is an array of rank 1, because it has one axis. That axis has a length of 3.
(2)
[ [1.,0.,0.],
[0.,1.,2.] ]
the array has rank 2 (it is 2-dimensional). The first dimension (axis) has a length of 2, the second dimension has a length of 3.
(3)NumPy’s array class is called ndarray. It is also known by the aliasarray. Note thatnumpy.array is not the same as the Standard Python Library classarray.array, which only handles one-dimensional arrays and offers less functionality. The more important attributes of anndarrayobject are:- ndarray.ndim
- ndarray.shape
- ndarray.size
- ndarray.dtype
- ndarray.itemsize
- ndarray.data
(4)numpy.arange
numpy.arange([start, ]stop, [step, ]dtype=None)
Return evenly spaced values within a given interval.
Parameters:start : number, optionalStart of interval. The interval includes this value. The default start value is 0.stop : numberEnd of interval. The interval does not include this value, except in some cases where step is not an integer and floating point round-off affects the length of out.step : number, optionalSpacing between values. For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. The default step size is 1. If step is specified, start must also be given.dtype : dtypeThe type of the output array. If dtype is not given, infer the data type from the other input arguments.Returns:
arange : ndarrayArray of evenly spaced values.For floating point arguments, the length of the result is ceil((stop - start)/step). Because of floating point overflow, this rule may result in the last element of out being greater than stop.
An example
>>> import numpy as np>>> a = np.arange(15).reshape(3, 5)>>> aarray([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14]])>>> a.shape(3, 5)>>> a.ndim2>>> a.dtype.name'int64'>>> a.itemsize8>>> a.size15>>> type(a)<type 'numpy.ndarray'>>>> b = np.array([6, 7, 8])>>> barray([6, 7, 8])>>> type(b)<type 'numpy.ndarray'>
1、Arrays
(1) initialize numpy arrays from nested Python lists, and access elements using square brackets(方括号[]):
code:
import numpy as npa = np.array([1, 2, 3]) # Create a rank 1 arrayprint type(a) # Prints "<type 'numpy.ndarray'>"print a.shape # Prints "(3,)"print a[0], a[1], a[2] # Prints "1 2 3"a[0] = 5 # Change an element of the arrayprint a # Prints "[5, 2, 3]"
b = np.array([[1,2,3],[4,5,6]]) # Create a rank 2 arrayprint b.shape # Prints "(2, 3)"print b[0, 0], b[0, 1], b[1, 0] # Prints "1 2 4"
result:
- NumPy学习笔记(一)
- Numpy学习笔记(一)
- Numpy学习笔记(一)
- numpy学习笔记(一)
- Numpy 学习笔记一
- numpy学习笔记一
- [Python] Numpy学习笔记(一)
- Numpy 学习指南 学习笔记(一)
- 学习笔记(一)NumPy库
- Numpy学习笔记一、Why Numpy?
- NumPy攻略学习笔记(一)
- NumPy学习(一)
- Numpy学习(一)
- numpy学习笔记一:numpy的基本用法
- numpy 学习日记(一)
- python学习-numpy(一)
- Numpy库学习(一)
- NumPy学习笔记(1)
- javaProject项目中,将jar包放入自定义目录下
- 自学Android之Activity:(三)使用Intent在Activity中跳转和传值(上)
- MFC的消息处理函数
- CCF 201612-4 压缩编码
- 读取js压缩为gzjs格式文件
- Numpy学习笔记(一)
- 2017网易游戏雷火盘古实习生招聘笔试:最大和
- [Mysql]SQL 中JOIN 的总结与使用
- MySQL外键设置中的 Cascade、NO ACTION、Restrict、SET NULL
- BZOJ 4318 OSU!
- MongoDB TTL索引
- java中equals方法的用法以及==的用法(转)
- 浅显理解 设计模式-工厂模式(一)
- 在VUE中遇到了一个过渡问题