We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The value you obtain from input() depends on what the user types in once the code is active. In our case, hackerrank automatically types in the values for us.
In the first example given by this problem, the first line of input that hackerrank automatically puts in when input() is called is '1 4' (which is converted to [1,4] using the split() and map() commands). The next time input() is called, it will ask for another submission, which hackerrank will automatically put in '1 2 3 4' for this example, and so on and so forth.
In other words, a1 = np.array([input().split() for _ in range(N)], int) calls the first N inputs, creating an array (in the example, N=1, so it only calls '1 2 3 4'). a2 = np.array([input().split() for _ in range(N)], int) calls the next N inputs, which is why it creates a different array (in this example, it would return '5 6 7 8' since that's the next input and N is still = 1).
Could you plase explain why we have looped over N and not M? From my understanding, a1 and a2 need to be 2 arrays with 4 elements each. This means we should loop over M.
'\n' is the new line escape sequence, and it's specified as the sep argument of the print function -- this is the character/sequences that separates elements of the output.
Adding sep='\n' to the print statement prints each element of the output on a new line.
If you're ever unsure of what a function is doing in example code you should look at the documentation. Print is a built-in function of python so you can simply google "python documentation print" :
As seen in the link, "sep", or "separator", is the parameter that specifies what separate the series of outputs by. The default is ' ' (a space), which will be used when you specific.
In this example, "hi" and "there" are outputs.
print("hi", "there", sep="x") => hixthere
"\n" means new line, so the outputs are each on a new line.
Array Mathematics
You are viewing a single comment's thread. Return to all comments →
Hey, please could you explain why a1 and a2 are different? How do 2 different arrays come out of the same 2 lines of code?
Thanks
The value you obtain from input() depends on what the user types in once the code is active. In our case, hackerrank automatically types in the values for us. In the first example given by this problem, the first line of input that hackerrank automatically puts in when input() is called is '1 4' (which is converted to [1,4] using the split() and map() commands). The next time input() is called, it will ask for another submission, which hackerrank will automatically put in '1 2 3 4' for this example, and so on and so forth.
In other words,
a1 = np.array([input().split() for _ in range(N)], int)
calls the first N inputs, creating an array (in the example, N=1, so it only calls '1 2 3 4').a2 = np.array([input().split() for _ in range(N)], int)
calls the next N inputs, which is why it creates a different array (in this example, it would return '5 6 7 8' since that's the next input and N is still = 1).In this case, N = 1 and M = 4.
Could you plase explain why we have looped over N and not M? From my understanding, a1 and a2 need to be 2 arrays with 4 elements each. This means we should loop over M.
The values the user or the computer will put in this case will be different to a1 and a2.
what is this sep='\n' mean??
'\n' is the new line escape sequence, and it's specified as the sep argument of the
print
function -- this is the character/sequences that separates elements of the output.Adding
sep='\n'
to the print statement prints each element of the output on a new line.If you're ever unsure of what a function is doing in example code you should look at the documentation. Print is a built-in function of python so you can simply google "python documentation print" :
https://docs.python.org/3/library/functions.html#print
As seen in the link, "sep", or "separator", is the parameter that specifies what separate the series of outputs by. The default is ' ' (a space), which will be used when you specific.
In this example, "hi" and "there" are outputs. print("hi", "there", sep="x") => hixthere
"\n" means new line, so the outputs are each on a new line.
sep='\n' means it will separate each input by by a newline character(escape sequence '\n').
WOW!! This is amazing.
I am not getting why we have to set the range(N) as N=1 Please can someone explain in detail?
why range N, INSTEAD OF M?
*[eval('a1'+i+'a2') could you explain what does this means?
Loved the way you used eval in this program.