数学函数应用(exp-e底数,sqrt-平方根函数)
import numpy as np//设置宏定义
B=np.arange(3)
print (B)//结果[0 1 2]
print (np.exp(B))//结果:[1. exp数据]
print (np.sqrt(B))//结果:[0. sqrt数据]
数据取整,维数转换
import numpy as np//设置宏定义
a=np.floor(10*np.random.random((3,4)))//np.random(3,4)的数据,矩阵3X4
//numpy.floor-向下取整(数据取整数处理)
//numpy.ceil-向上取整
print (a)//结果:[6. 7. 2. 9]
[6. 0. 5. 2]
[9. 0. 9. 6]
print(“------------”)
print (a.ravel)//结果:[6. 7. 2. 9. 6. 0. 5. 2. 9. 0. 9. 6]
//.ravel-将多维数组降位一维
//.flattenh-将多维数组降位一维(优先级高于ravel,并保持原有矩阵)
print(“------------”)
a.shape=(6,2)//a:矩阵定义名称 shape:矩阵打印函数
print (a)//结果:[6. 7]
[2. 9]
[6. 0]
[5. 2]
[9. 0]
[9. 6]
print(“------------”)
print (a,T)//结果:[[6. 2. 6. 5. 9. 9.][7. 9. 0. 2. 0. 6.]]
numpy.floor
numpy.floor(x, /, out=None, *, where=True, casting=‘same_kind’, order=‘K’, dtype=None, subok=True[, signature, extobj]) =
Return the floor of the input, element-wise.
The floor of the scalar x is the largest integer i, such that i <= x. It is often denoted as \lfloor x \rfloor.
Parameters:
x : array_like
Input data.
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 : ndarray or scalar
The floor of each element in x. This is a scalar if x is a scalar.
See also
ceil, trunc, rint
Notes
Some spreadsheet programs calculate the “floor-towards-zero”, in other words floor(-2.5) == -2. NumPy instead uses the definition of floor where floor(-2.5) == -3.
Examples
a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0])
np.floor(a)
array([-2., -2., -1., 0., 1., 1., 2.])
import numpy as np//设置宏定义
a = np.floor(10*np.random.random((2,2)))//数据内容10*(2-2)的随机;数据矩阵2X2
b = np.floor(10*np.random.random((2,2)))//数据内容10*(2-2)的随机;数据矩阵2X2
print (a)//结果:[3. 1]
// [0. 1]
print(“------------”)
print (b)//结果:[4. 2]
[9. 2]
print(“------------”)
print (np.hstack((a,b)))//结果:[3. 1. 4. 2]
// [0. 1. 9. 2]
.hstack(a,b)-stack针对数据(a,b)叠加。hstack叠加方向行向(h)
.vstack(a,b)-stack针对数据(a,b)叠加。vstack叠加方向纵向(v)
import numpy as np//设置宏定义
a = np.floor(10*np.random.random((2,12)))//数据内容10*(2-12)的随机;数据矩阵2X12
print (a)//结果:数据内容10*(2-12)的随机;数据矩阵2X12
print(“------------”)
print (np.hsplit(a,3))//矩阵数据a拆分,拆分数量为3(3等份的矩阵),方向为行
print(“------------”)
print (np.hsplit(a,(3,4)))//矩阵数据a拆分,拆分数量为(3,4)(矩阵第3,4行),方向为行
a = np.floor(10*np.random.random((12,2)))//数据内容10*(12-2)的随机;数据矩阵12X2
print(“------------”)
print (a)//结果:数据内容10*(2-12)的随机;数据矩阵12X2
np.vsplit(a,3)//矩阵数据a拆分,拆分数量为3(3等份的矩阵),方向为纵
.hsplit(a,b)-split针对矩阵数据a拆分,拆分数量为b(b等份的矩阵)。hspli拆方向行向(h)
.hsplit(a,(b,c))-split针对矩阵数据a拆分,拆分数量为(b,c)(矩阵第b,c行)。hspli拆方向行向(h)
.vsplit(a,b)-split针对矩阵数据a拆分,拆分数量为b(b等份的矩阵)。vspli拆方向纵向(v)
.vsplit(a,(b,c))-split针对矩阵数据a拆分,拆分数量为(b,c)(矩阵第b,c列)。hspli拆方向纵向(v)
—未完待续(2018.10.16.21点11分)