Python grammar

One of the above method calls is inside the parentheses, the other is outside the parentheses, and the other is without parentheses. Can you explain what the syntax is? For the above different situations, what should I use next time

I think y**2 in this context is an operator which is equivalent to the pow() function.

in y=sum(x**2) you’re raising every element of tensor x to 2 and then passing it to the sum function.

in x**2.sum() you raise every element of x to 2 (because it’s a tensor) and then when you get the result back as a tensor you apply the sum() method to each element of that returned tensor.

both x and y are tensors.

I’m not really sure what that ‘or’ is doing there though, maybe it’s just to illustrate?

BTW, I’m sure this comes with experience in Python, but this is something about this language which really drives me up the wall. It’s hard to tell what’s a method, what’s a property and they seem to be arbitrarily sprinkled around. Some libraries would have a method with a name and another library would have a property with the exact same name and they do pretty much the same thing, and you have to find out each one every time for yourself. There aren’t any conventions to name properties and methods certain way. I’m a bit of a fan of the “Hungarian Notation” simply because you can tell what the heck something does mostly from its name. /rant

“or”:it’s just to illustrate
Thanks very much

Hi Lizhupfeng.

A function require () and a property does not.
A function may have arguments or “.function()” means applied to the variable.
So if x is a multi valued thing with 0 - scalar, 1 - array, 2 - matrix 3- tensor then “.function()” is applied to x.
x =1 and x.function is the same as function(x)

If x is a variable it can have a property so consider x is a person then x.age is their age.

Of course a property could be a multi-valued so CourseAI.ageOfStudents is [16,16,18,21,50,88] so you could have CourseAI.ageOfStudents.average()

I hope that helps.

Regards Conwyn