通用函數是一種對ndarry中的數據執行元素級運算的函數,能夠看做是簡單函數(接受一個或多個標量值,併產生一個或多個標量值)的矢量化包裝器。python
In [19]: np.abs(12.0) Out[19]: 12.0 In [20]: np.abs(12) Out[20]: 12 In [21]: np.abs(12+5j) #其中12+5j就是複數,其中12爲實數部分,5爲虛數部分 Out[21]: 13.0 In [22]: np.abs(12-5j) Out[22]: 13.0
In [36]: np.sqrt(4) Out[36]: 2.0 In [37]: np.sqrt(5) Out[37]: 2.23606797749979
In [38]: np.square(4) Out[38]: 16 In [39]: np.square(2.6) Out[39]: 6.760000000000001
In [40]: np.exp(2) Out[40]: 7.38905609893065 #python3還有個函數爲exp2,計算的是2的指數 In [41]: np.exp2(5) Out[41]: 32.0
In [42]: np.log(2) Out[42]: 0.6931471805599453 In [43]: np.log10(0.1) Out[43]: -1.0
In [44]: np.sign(12) Out[44]: 1 In [45]: np.sign(-12) Out[45]: -1 In [46]: np.sign(0) Out[46]: 0
In [47]: np.ceil(15.971) Out[47]: 16.0
In [48]: np.floor(-1.564) Out[48]: -2.0 In [49]: np.floor(1.564) Out[49]: 1.0
In [50]: np.rint(1.485) Out[50]: 1.0
In [52]: np.modf([1.5,2.9]) Out[52]: (array([0.5, 0.9]), array([1., 2.]))
In [56]: np.isnan(NaN) Out[56]: True In [57]: np.isnan(12) Out[57]: False
In [61]: np.isfinite(1/3) Out[61]: True In [62]: np.isinf(1/3) Out[62]: False In [63]: np.isinf(1/2) Out[63]: False In [64]: np.isfinite(1/2) Out[64]: True
In [65]: np.sin(30) Out[65]: -0.9880316240928618 In [66]: np.sin(1/2) Out[66]: 0.479425538604203 In [67]: np.sin(1/6) Out[67]: 0.16589613269341502 In [68]: np.cos(1/3) Out[68]: 0.9449569463147377
In [71]: np.logical_not(15) Out[71]: False In [72]: np.logical_not(-15) Out[72]: False In [73]: np.logical_not(-1) Out[73]: False In [74]: np.logical_not(0) Out[74]: True
#以上傳入的參數均可以是數組,只不過爲了測試方便才傳入一個值數組