Complex indexing

Here, we illustrate the use of complex indexing to assign values from a smaller array into a larger one:

    In [188]: ar=np.arange(15); ar
    Out[188]: array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])
    
    In [193]: ar2=np.arange(0,-10,-1)[::-1]; ar2
    Out[193]: array([-9, -8, -7, -6, -5, -4, -3, -2, -1,  0]) 

Slice out the first 10 elements of ar, and replace them with elements from ar2, as follows:

    In [194]: ar[:10]=ar2; ar
    Out[194]: array([-9, -8, -7, -6, -5, -4, -3, -2, -1,  0, 10, 11, 12, 13, 14])  

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset