function - Use size in Python -


i created ndarray array in python

temp = np.array([1, 2, 3, 4]) 

to measure length of array, can use

temp.size 

or

np.size(temp) 

both return 4. i'm wondering what's difference between 2 expressions? also, lena image, need write

>>> import scipy.misc >>> lena = scipy.misc.lena() 

i'm wondering why there's bracket pair after lena? isn't lena matrix? () function. understand lena() function takes no inputs , returns ndarray. feel it's tedious write way.

in matlab, it's quite clear distinguish between constant , function. function defined , called (), constant (or pre-stored) can called directly, e.g., "blobs.png"

np.size(temp) little more general temp.size. @ first glance, appear same thing:

>>> x = np.array([[1,2,3],[4,5,6]]) >>> x.size 6 >>> np.size(x) 6 

this true when don't supply additional arguments np.size. if @ documentation np.size, you'll see accepts additional axis parameter, gives size along corresponding axis:

>>> np.size(x, 0) 2 >>> np.size(x, 1) 3 

as far second question, scipy.misc.lena is function point out. not matrix. function returning matrix. function (presumably) loads data on fly isn't placed in memory whenever import scipy.misc module. good thing, , not different matlab.