numpy库应用03

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33897358/article/details/83049399

1. 创造向量数据

import numpy as np//设置宏定义np == numpy
print (np.arange(15))
---结果:[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]

2.创造矩阵数据

import numpy as np
print (np.arange(15))
a=np.arange(15).reshape(3,5)
---结果:[[0,1,2,3,4],
        [5,6,7,8 ,9], 
        [10, 11, 12, 13, 14]]

3.打印数据包含的元素数量

a,size //a:矩阵定义名称 size:矩阵数据包含元素数量

4.初始化无数据矩阵

  1. 内部数据0

     import numpy as np//设置宏定义
     np == np.zeros((3,4))
     ---结果:3X4,数据为0的矩阵
    
  2. 内部数据1

     import numpy as np//设置宏定义
     np.ones((2,3,4),dtype=np.int32)
     ---结果:2X3X4,数据为1的矩阵
    

5.创造数据自加

    import numpy as np//设置宏定义
    np.arange([10,30,5])//起始值10;终止值<30;p=5
    ---结果array([10,15,20,25])

公式:np.arange([A,C,B]) //A:起始值; B:p值;C:终止值<C

6.随机数据

  1. nump.random-根据数据内容范围确定矩阵(整数)

     import numpy as np//设置宏定义
     np.random.random (2,3)//np.random(2,3)的数据,矩阵2X3
     ---结果:2X3,数据为2-3的矩阵
    
  2. nump.linspace-根据数据内容范围确定矩阵(数据点)

     import numpy as np//设置宏定义
     from numpy import pi//设置宏定义
     np.linspace(0,2*pi,100)//利用np.linspace设置0-2*pi,取100个数据点
    
  3. np.sin(np.linspace-根据数据内容范围确定矩阵(数据点+函数应用)===nump.sin

     import numpy as np//设置宏定义
     from numpy import pi//设置宏定义   
     np.sin(np.linspace(0,2*pi,100))//利用np.linspace设置0-2*pi,取100个数据点
    

numpy.sin

numpy.sin(x, /, out=None, *, where=True, casting=‘same_kind’, order=‘K’, dtype=None, subok=True[, signature, extobj]) = <ufunc ‘sin’>
Trigonometric sine, element-wise.

Parameters:
x : array_like
Angle, in radians (2 \pi rad equals 360 degrees).
out : ndarray, None, or tuple of ndarray and None, optional
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
where : array_like, optional
Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone.
**kwargs
For other keyword-only arguments, see the ufunc docs.
Returns:
y : array_like
The sine of each element of x. This is a scalar if x is a scalar.
See also
arcsin, sinh, cos

Notes

The sine is one of the fundamental functions of trigonometry (the mathematical study of triangles). Consider a circle of radius 1 centered on the origin. A ray comes in from the +x axis, makes an angle at the origin (measured counter-clockwise from that axis), and departs from the origin. The y coordinate of the outgoing ray’s intersection with the unit circle is the sine of that angle. It ranges from -1 for x=3\pi / 2 to +1 for \pi / 2. The function has zeroes where the angle is a multiple of \pi. Sines of angles between \pi and 2\pi are negative. The numerous properties of the sine and related functions are included in any standard trigonometry text.

7.Numpy基本的组合运算

  1. 初始值为同类型数据

     import numpy as np//设置宏定义
     a=np.array([20,30,40,50])
     b=np.array(4)
     print(a)//结果[20 30 40 50]
     print(b)//结果[0 1 2 3]
     c=a-b
     print(c)//结果[20 29 38 47]
     c=c-1
     print(c)//结果[19 28 37 46]
     b**2
     print(b**2)//结果[0 1 4 9]
     print(a<35)//结果N N T T
    
  2. 初始值为数组同类型数据

     import numpy as np//设置宏定义
     a=np.array([1,1],[0,1])
     b=np.array([2,0],[3,4])
     print (a)//结果1X1的[1 1][0 1]
     print ('--------')//结果--------
     print (b)//结果1X1的[2 0][3 4]
     print ('--------')//结果--------
     print (a*b)//结果1X1的[2 0][0 4]
     print ('--------')//结果--------
     print (a.dot(b))//结果1X1的[5 4][3 4]
     print ('--------')//结果--------
     print (np.dot)//结果1X1的[5 4][3 4]
                   //np.dot值数据替换
    

—未完待续(2018.10.14.18点26分)

猜你喜欢

转载自blog.csdn.net/qq_33897358/article/details/83049399