NUMPY_3

import numpy as np
a = np.arange(15).reshape(3, 5)
a
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])
a.shape
(3, 5)
#the number of axes (dimensions) of the array
a.ndim
2
a.dtype.name
dtype('int32')
#the total number of elements of the array
a.size
15
np.zeros ((3,4)) 
array([[0., 0., 0., 0.],
       [0., 0., 0., 0.],
       [0., 0., 0., 0.]])
np.ones( (2,3,4), dtype=np.int32 )
array([[[1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1]],

       [[1, 1, 1, 1],
        [1, 1, 1, 1],
        [1, 1, 1, 1]]])
#To create sequences of numbers
np.arange( 10, 30, 5 )
array([10, 15, 20, 25])
np.arange( 0, 2, 0.3 )
array([0. , 0.3, 0.6, 0.9, 1.2, 1.5, 1.8])
np.arange(12).reshape(4,3)
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
np.random.random((2,3))
array([[ 0.40130659,  0.45452825,  0.79776512],
       [ 0.63220592,  0.74591134,  0.64130737]])
from numpy import pi
np.linspace( 0, 2*pi, 2 )
array([0.        , 6.28318531])
np.sin(np.linspace( 0, 2*pi, 100 ))
array([  0.00000000e+00,   6.34239197e-02,   1.26592454e-01,
         1.89251244e-01,   2.51147987e-01,   3.12033446e-01,
         3.71662456e-01,   4.29794912e-01,   4.86196736e-01,
         5.40640817e-01,   5.92907929e-01,   6.42787610e-01,
         6.90079011e-01,   7.34591709e-01,   7.76146464e-01,
         8.14575952e-01,   8.49725430e-01,   8.81453363e-01,
         9.09631995e-01,   9.34147860e-01,   9.54902241e-01,
         9.71811568e-01,   9.84807753e-01,   9.93838464e-01,
         9.98867339e-01,   9.99874128e-01,   9.96854776e-01,
         9.89821442e-01,   9.78802446e-01,   9.63842159e-01,
         9.45000819e-01,   9.22354294e-01,   8.95993774e-01,
         8.66025404e-01,   8.32569855e-01,   7.95761841e-01,
         7.55749574e-01,   7.12694171e-01,   6.66769001e-01,
         6.18158986e-01,   5.67059864e-01,   5.13677392e-01,
         4.58226522e-01,   4.00930535e-01,   3.42020143e-01,
         2.81732557e-01,   2.20310533e-01,   1.58001396e-01,
         9.50560433e-02,   3.17279335e-02,  -3.17279335e-02,
        -9.50560433e-02,  -1.58001396e-01,  -2.20310533e-01,
        -2.81732557e-01,  -3.42020143e-01,  -4.00930535e-01,
        -4.58226522e-01,  -5.13677392e-01,  -5.67059864e-01,
        -6.18158986e-01,  -6.66769001e-01,  -7.12694171e-01,
        -7.55749574e-01,  -7.95761841e-01,  -8.32569855e-01,
        -8.66025404e-01,  -8.95993774e-01,  -9.22354294e-01,
        -9.45000819e-01,  -9.63842159e-01,  -9.78802446e-01,
        -9.89821442e-01,  -9.96854776e-01,  -9.99874128e-01,
        -9.98867339e-01,  -9.93838464e-01,  -9.84807753e-01,
        -9.71811568e-01,  -9.54902241e-01,  -9.34147860e-01,
        -9.09631995e-01,  -8.81453363e-01,  -8.49725430e-01,
        -8.14575952e-01,  -7.76146464e-01,  -7.34591709e-01,
        -6.90079011e-01,  -6.42787610e-01,  -5.92907929e-01,
        -5.40640817e-01,  -4.86196736e-01,  -4.29794912e-01,
        -3.71662456e-01,  -3.12033446e-01,  -2.51147987e-01,
        -1.89251244e-01,  -1.26592454e-01,  -6.34239197e-02,
        -2.44929360e-16])
#the product operator * operates elementwise in NumPy arrays
a = np.array( [20,30,40,50] )
b = np.arange( 4 )
#print a 
print(b) 
#b
c = a-b
print(c)
b**2
#print b**2
print (a<35)
[0 1 2 3]
[20 29 38 47]
[ True  True False False]
#The matrix product can be performed using the dot function or method
A = np.array( [[2,5],
               [1,4]] )
B = np.array( [[2,1],
               [3,4]] )

#print A*B
print(A.dot(B)) 
print(np.dot(A, B))
[[19 22]
 [14 17]]
[[19 22]
 [14 17]]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值