python - numpy.r_ is not a function. What is it? -
according numpy/scipy doc on numpy.r_ here, "not function, takes no parameters".
if not function, proper term "functions" such numpy.r_?
it's class instance (aka object):
in [2]: numpy.r_ out[2]: <numpy.lib.index_tricks.rclass @ 0x1923710> a class construct used define distinct type - such class allows instances of itself. each instance can have properties (member/instance variables , methods).
one of methods class can have __getitem__ method, called whenever append [something,something...something] name of instance. in case of numpy.r_ instance method returns numpy array.
take following class example:
class myclass(object) def __getitem__(self,i) return i*2 look @ these outputs above class:
in [1]: = myclass() in [2]: a[3] out[2]: 6 in [3]: a[3,4] out[3]: (3, 4, 3, 4) i calling __getitem__ method of myclass (via [] parentheses) , __getitem__ method returning (the contents of list * 2 in case)- not class/instance behaving function - __getitem__ function of myclass instance being called.
on final note, notice instantiate myclass had a = myclass() whereas instance of rclass use numpy.r_ because numpy instantiates rclass , binds name numpy.r_ itself. this relevant line in numpy source code. in opinion rather ugly , confusing!
Comments
Post a Comment