[Numpy-discussion] array of tuples

Christopher Barker Chris.Barker at noaa.gov
Tue Jun 6 15:21:56 CDT 2006



Travis N. Vaught wrote:
> I'd like to construct an array of tuples and I'm not sure how (without 
> looping). 

Is this what you want?

 >>> import numpy as N
 >>> a = N.empty((2,),dtype=object)
 >>> a[:] = [(1,2,3),(4,5,6)]
 >>> a
array([(1, 2, 3), (4, 5, 6)], dtype=object)
 >>> a.shape
(2,)

By the way, I notice that the object dtype is not in the numpy 
namespace. While this mikes sense, as it's part of python, I keep 
getting confused because I do need to use numpy-specific dtypes for 
other things. I never use import *, so it might be a good idea to put 
the standard objects dtypes in the numpy namespace too. Or maybe not, 
just thinking out loud.

Note: PyObject is there, but isn't that a deprecated Numeric name?

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the Numpy-discussion mailing list