I have a numpy array like this:
candidates =
array([[1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0,
0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0],
[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1],
[1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0]])
And I do not understand what is the difference between candidates[0]:
candidates[0] =
array([1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0,
0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0]
candidates[0].shape = (34,)
And candidates[0:1]:
candidates[0:1] =
array([[1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0,
0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0]])
candidates[0:1].shape = (1, 34)
because I believe the two should give the exact same results? I mean the later i.e. candidates[0:1] is supposed to represent the first element only, right? So, what is the difference between the two exactly?
candidates[0]is the first element (in this case, the first row);candidates[0:1]is a collection of the first one elements (in this case, a 2D array containing only the first row). That's why the shapes are different. Comparelst = [1,2,3]thenlst[0]vs.lst[0:1]: one is1, the other is[1].[0]and[0:1]return different shapes, or about why(34,)and(1,34)are different shapes. The linked question answers only the latter.[0]and[0:1]. I just needed to understand that the later results in a 2D array. Idk maybe I should remove the word 'size' from the question to avoid confusion? Or if you think you can improve my wording pls go ahead as English is not my first language haha. Thank you!