Python: ndarray operation

Ndarray is most used data type in python, because many modules such as pylab, numpy use ndarray as default data type to undertake matrix operation. So using ndarray type of data will quickly accelerate the speed of python calculation.

  • Read part of indices from an ndarray matrix
    Suppose we have a matrix in ndarray type as M: 10*20, X:10, if we just wish to get the first dimension of this matrix we can set the code like this:
    M[0:3,:].shape=(3,20)
    X[0:3].shape=(3)
    The index begin with 0 end with 2, the last index 3 is not included!

  • reorder ndarray matrix
    x=numpy.array([0,1,2,3])
    y=numpy.array([[0,1,2,3],[0,2,4,6]])
    xf=numpy.fliplr(x)
    error Input must be >=2-d, this error might suggest that function fliplr can only work on matrix whose dimension bigger or equal than 2
    yf=array([][3,2,1,0],[6,4,2,0])

  • combine two ndarray
    A=numpy.concatenate([A1,A2])

posted on 2017-07-12 21:27  DocNan  阅读(249)  评论(0编辑  收藏  举报

导航