I am not sure I understand your question entirely. But, in the documentation, usually, there is a link to the source code for that particular function/method.
So, you could check out the source code to see how it works under the hood. However, I would argue that’s not necessary or even recommended given how difficult it can be to sift through the code of such libraries.
In the documentation it’s specified that one of the input parameters to
np.mean() is -
- a: array_like
Array containing numbers whose mean is desired. If a is not an array, a conversion is attempted.
Since your input is a list, it converts the list to an array and then calculates the mean of that array.
In the above, you are converting
listname into an array using
np.array() and then calculating the mean of that array.
It really depends, I think, on what you want to do with
listname. In both cases above,
listname is not saved into an array. So, both use-cases are viable. But,
np.mean() is just cleaner/more direct.
If you wanted to continue using the array you get from
listname, then it likely makes better sense to first convert it into an array and then calculate the mean of that array separately.
arrayname = np.array(listname)
arraymean = arrayname.mean()
Both approaches, I believe, are essentially the same but
np.mean() is better/simpler/cleaner/obvious/direct if you don’t plan on storing the array.
It is possible that one approach is somehow less memory intensive than the other but I doubt that to be the case for the above or similar scenarios. I would recommend either searching for that on other websites like stackoverflow or you can post such questions on those websites if this is a topic of interest for you. “Under the hood” discussions sort of reach a ceiling in such forums since that’s not the primary focus.
If I misunderstood your question, feel free to clarify!