slicing on two dimensional array in Numpy Python by R4R Team

Syntax-

arr[rs:es:gap,cs:ce:gap]

-Here rs and es are the row starting and row ending points which are used to select the rows of the matrix.
-and cs and ce are the column starting and column ending points which select the column of the matrix.


program-

#import numpy
import numpy as np

l=[[1,2,3],[4,5,6],[1,1,1]]
arr=np.array(l)
print("nGiven array isn",arr)

s=arr[::,::]
print("After first slicingn",s)

s=arr[1:3,::]
print("After Second slicingn",s)

s=arr[0:3:1,0:1:1]
print("After Third slicingn",s)


output-

Given array is
[[1 2 3]
[4 5 6]
[1 1 1]]
After first slicing
[[1 2 3]
[4 5 6]
[1 1 1]]
After Second slicing
[[4 5 6]
[1 1 1]]
After Second slicing
[[1]
[4]
[1]]




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!