Transpose and Flatten

  • + 7 comments

    Its will not be troublesome if you divide it line by line(sorry for lil' long explanation :p -> 1-array creation

    narr = numpy.array("data for array", "its data type") is a general template for numpy array creation.

    The "[raw_input().split() for _ in xrange(int(raw_input().split()[0]))]" is used to create data elements and after that its data type "int" is specified

    2- Now inside the square brackets , a concept of list comprehension is used.In this a for loop is used to fetch the elements of list.

    for eg:- myList = [x for x in range(9)] will create a list of elements ranging from 0 to 8 like this myList = [0,1,2,3,4,5,6,7,8]

    Now when we compare this eg statment with our main solution statement:-

    '''But before that, lets understand the raw_input().split() the raw_input() is used to take input from user and split() is use to split that input statement when ever a "blank space" occurs. so the raw_input().split() will create a list of the input element which are separate with black space

    for eg t = (raw_input().split()) then t will contain the user input element

    And if we say 't[0]' it will point the first element the user inserted(basic array iteration) '''

    Now back to comparison: the x in our eg statement is equivalent to raw_input().split() which will form the elements of the array

    and 9 is the 'raw_input().split()[0]' is basically a counter of how many time the x or the raw_input().split() is executed and inserted to array

    We have taken the first element as the input in our "xrange" function because the element represents the rows of our array(n) and the second represents (m) which is of no use here. so the first raw_input().split() represents 1 entry for each column and second raw_input().split()[0] represents the number of rows

    Hope it helps :)

    p.s. if you have still dont understand you can reply