python使用

  1. numpy.shape

    
    >>> import numpy as np
    >>> a = np.array([1, 2, 3, 4])
    >>> a.shape
    (4,)
    >>> a.shape[0]
    4
    >>> c = np.array([[1, 2, 3, 4],[4, 5, 6, 7], [7, 8, 9, 10]])
    >>> c.shape
    (3, 4)
    >>> c.shape[0]
    3
    >>> c.shape[1]
    4
  2. range

    
    >>> range(1,5) #代表从1到5(不包含5)
    [1, 2, 3, 4]
    >>> range(1,5,2) #代表从1到5,间隔2(不包含5)
    [1, 3]
    >>> range(5) #代表从0到5(不包含5)
    [0, 1, 2, 3, 4]
  3. numpy.sum() 求和

    >>> a
    array([[6, 7, 1, 6],
           [1, 0, 2, 3],
           [7, 8, 2, 1]])
    >>> np.sum(a)
    44
    >>> np.sum(a,axis=0)
    array([14, 15,  5, 10])
    >>> np.sum(a,axis=1)
    array([20,  6, 18])
    >>> np.sum(a,axis=-1)
  4. numpy.mean() 均值

    >>> a
    array([[6, 7, 1, 6],
           [1, 0, 2, 3],
           [7, 8, 2, 1]])
    >>> np.mean(a)
    3.6666666666666665
    >>> np.mean(a,axis=0)
    array([ 4.66666667,  5.        ,  1.66666667,  3.33333333])
  5. numpy.var() 方差

    >>> np.var(a)
    7.7222222222222223
    >>> np.var(a,axis=0)
    array([  6.88888889,  12.66666667,   0.22222222,   4.22222222])
  6. numpy.std() 标准差

    >>> np.std(a,axis=0)
    array([ 2.62466929,  3.55902608,  0.47140452,  2.05480467])

    参考 python 科学计算学习一:numpy快速处理数据(3)

  7. numpy.max() 最大值
  8. numpy.min() 最小值
  9. numpy.argmax() 最大值的下标
  10. numpy.argmin() 最小值的下标
  11. numpy.sort() 排序

    >>> a
    array([[6, 7, 1, 6],
           [1, 0, 2, 3],
           [7, 8, 2, 1]])
    >>> a.sort()
    >>> a
    array([[1, 6, 6, 7],
           [0, 1, 2, 3],
           [1, 2, 7, 8]])
    >>> np.sort(a,axis=0)
    array([[0, 1, 2, 3],
           [1, 2, 6, 7],
           [1, 6, 7, 8]])
    
  12. numpy.argsort() 排序后的数据原来位置的下标

    >>> np.argsort(a,axis=0)
    array([[1, 1, 1, 1],
           [0, 2, 0, 0],
           [2, 0, 2, 2]])
  13. pickle.load(file) Read a string from the open file object file and interpret it as a pickle data stream, reconstructing and returning the original object hierarchy

    Welcome To PyCrust 0.7.2 - The Flakiest Python Shell
    Sponsored by Orbtech - Your source for Python programming expertise.
    Python 2.2.1 (#1, Aug 27 2002, 10:22:32)
    [GCC 3.2 (Mandrake Linux 9.0 3.2-1mdk)] on linux-i386
    Type "copyright", "credits" or "license" for more information.
    >>> import cPickle as pickle
    >>> t1 = ('this is a string', 42, [1, 2, 3], None)
    >>> t1
    ('this is a string', 42, [1, 2, 3], None)
    >>> p1 = pickle.dumps(t1)
    >>> p1
    "(S'this is a string'\nI42\n(lp1\nI1\naI2\naI3\naNtp2\n."
    >>> print p1
    (S'this is a string'
    I42
    (lp1
    I1
    aI2
    aI3
    aNtp2
    .
    >>> t2 = pickle.loads(p1)
    >>> t2
    ('this is a string', 42, [1, 2, 3], None)
    >>> p2 = pickle.dumps(t1, True)
    >>> p2
    '(U\x10this is a stringK*]q\x01(K\x01K\x02K\x03eNtq\x02.'
    >>> t3 = pickle.loads(p2)
    >>> t3
    ('this is a string', 42, [1, 2, 3], None)
  14. 14.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值