Understanding why this was written this way

Course Name: Python for Trading: Basic, Section No: 7, Unit No: 15, Unit type: Notebook



Alright, posting this so that someone else can also get benefits out of 'why' this was written this way. So, after 20 mins of reading various contents around 'why' - I have learnt that numpy's array data structure is essentially a combination of shape property (which gives the row x cols property) and the contents which is defined as tuples (i.e. immutable lists) of N positive integers. So when you write 2*(10+2), 10+2 is simply a number. But when you write 2*(10+2,) then you mean that 2 should be multiplied by a tuple which has one element (12). 



Now, the same logic is extended to lists but if you would have written the same command without trailing comma i.e. B=np.array([[1,2,3]]*3) then it should have given the same output. So for tuples representation, comma is a must but for lists it is not needed but can be given optionally as given in the example code.

Hi Prasanna,



This is very insightful information. Thanks!