From: Andrea R. <ari...@pi...> - 2004-03-11 12:16:59
|
Hi, it is surely a silly question, but I'm quite new to Python and Numpy. So I hope you can help me, I've searched Numpy's manual without successs. Suppose I want to test if a paremeter inside a function is an array or not. How can I test this? type(my_array) is array returns 'False'!! Thanks in advance, Andrea. --- Andrea Riciputi "Science is like sex: sometimes something useful comes out, but that is not the reason we are doing it" -- (Richard Feynman) |
From: Paulo J. S. S. <rs...@im...> - 2004-03-11 12:52:57
|
Hi, Funny, I have just entered the list and I can answer this one! Try type(my_array) is arraytype That worked to me. Best, Paulo --=20 Paulo Jos=E9 da Silva e Silva=20 Professor Assistente do Dep. de Ci=EAncia da Computa=E7=E3o (Assistant Professor of the Computer Science Dept.) Universidade de S=E3o Paulo - Brazil e-mail: rs...@im... Web: http://www.ime.usp.br/~rsilva Teoria =E9 o que n=E3o entendemos o (Theory is something we don't) suficiente para chamar de pr=E1tica. (understand well enough to call)=20 (practice) |
From: Andrea R. <ari...@pi...> - 2004-03-11 13:36:12
|
You are right! But I can't understand why. When I try type() with an=20 array I get: type(my_array) <type 'array'> but: type(my_array) is array False Can someone explain this? Cheers, Andrea. On 11 Mar 2004, at 13:42, Paulo J. S. Silva wrote: > Hi, > > Funny, I have just entered the list and I can answer this one! > > Try > > type(my_array) is arraytype > > That worked to me. > > Best, > > Paulo > --=20 > Paulo Jos=E9 da Silva e Silva > Professor Assistente do Dep. de Ci=EAncia da Computa=E7=E3o > (Assistant Professor of the Computer Science Dept.) > Universidade de S=E3o Paulo - Brazil > > e-mail: rs...@im... Web: http://www.ime.usp.br/~rsilva > > Teoria =E9 o que n=E3o entendemos o (Theory is something we don't) > suficiente para chamar de pr=E1tica. (understand well enough to call) > (practice) > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id638&op=3Dclick > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > > --- Andrea Riciputi "Science is like sex: sometimes something useful comes out, but that is not the reason we are doing it" -- (Richard Feynman) |
From: Alexandre <Ale...@lo...> - 2004-03-11 13:54:07
|
On Thu, Mar 11, 2004 at 02:25:53PM +0100, Andrea Riciputi wrote: > You are right! But I can't understand why. When I try type() with an=20 > array I get: >=20 > type(my_array) > <type 'array'> >=20 > but: >=20 > type(my_array) is array > False >=20 > Can someone explain this? array is a function. try "type(array)", and print(array) to check.=20 --=20 Alexandre Fayolle LOGILAB, Paris (France). http://www.logilab.com http://www.logilab.fr http://www.logilab.org |
From: Paulo J. S. S. <rs...@im...> - 2004-03-11 14:18:22
|
This is a more tricky question. If I understand well enough. The name "array" in a python section relates to a factory function that builds arraytype objects. It is not the name for the array type. For example, if you type: type(array) you get <type 'builtin_function_or_method'> Which shows that it is a function, not a class object. There are more subtlety associated to the fact that Numeric does not use the new class styles as numarray does. Actually if you use numarray instead of Numeric you'll get a more sensible behavior >>> import numarray >>> a =3D numarray.array([1.,2.,3.]) >>> type(a) <class 'numarray.numarraycore.NumArray'> >>> type(a) is numarray.NumArray True >>> isinstance(a, numarray.NumArray) True >>> Best regards, Paulo Obs: You may consider using a "try: except:" statement instead of always checking type. In Python is usually better to ask "forgiveness" in a "except" clause than to ask "permission" by checking types. --=20 Paulo Jos=E9 da Silva e Silva=20 Professor Assistente do Dep. de Ci=EAncia da Computa=E7=E3o (Assistant Professor of the Computer Science Dept.) Universidade de S=E3o Paulo - Brazil e-mail: rs...@im... Web: http://www.ime.usp.br/~rsilva Teoria =E9 o que n=E3o entendemos o (Theory is something we don't) suficiente para chamar de pr=E1tica. (understand well enough to call)=20 (practice) |
From: <fe...@la...> - 2004-03-11 15:22:32
|
As others have pointed out, array is a function. You want ArrayType. > type(my_array) is ArrayType > True -r Andrea Riciputi writes: > You are right! But I can't understand why. When I try type() with an=20 > array I get: > > type(my_array) > <type 'array'> > > but: > > type(my_array) is array > False > > Can someone explain this? > > Cheers, > Andrea. > > On 11 Mar 2004, at 13:42, Paulo J. S. Silva wrote: > > > Hi, > > > > Funny, I have just entered the list and I can answer this one! > > > > Try > > > > type(my_array) is arraytype > > > > That worked to me. > > > > Best, > > > > Paulo > > --=20 > > Paulo Jos=E9 da Silva e Silva > > Professor Assistente do Dep. de Ci=EAncia da Computa=E7=E3o > > (Assistant Professor of the Computer Science Dept.) > > Universidade de S=E3o Paulo - Brazil > > > > e-mail: rs...@im... Web: http://www.ime.usp.br/~rsilva > > > > Teoria =E9 o que n=E3o entendemos o (Theory is something we don't) > > suficiente para chamar de pr=E1tica. (understand well enough to call) > > (practice) > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by: IBM Linux Tutorials > > Free Linux tutorial presented by Daniel Robbins, President and CEO of > > GenToo technologies. Learn everything from fundamentals to system > > administration.http://ads.osdn.com/?ad_id=1470&alloc_id638&op=3Dclick > > _______________________________________________ > > Numpy-discussion mailing list > > Num...@li... > > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > > > > > --- > Andrea Riciputi > > "Science is like sex: sometimes something useful comes out, > but that is not the reason we are doing it" -- (Richard Feynman) > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > > |