[AstroPy] Constructing an astropy table with colnames and dtypes of existing table

Andrew Hearin andrew.hearin at yale.edu
Wed Apr 29 13:53:13 EDT 2015

Hi Alexa,

If your table instances is called t, how about the following:

t2 = Table(np.empty_like(t.as_array()))


On Apr 29, 2015, at 1:40 PM, Alexa Villaume <avillaum at ucsc.edu> wrote:

> Hi everybody,
> I’m trying to construct an astropy table using the exact same columns and corresponding dtypes of an existing table. The documentation goes into using existing columns but it wasn’t as clear to me on how to handle the data types. For example, I have an existing table ‘irtf’ and I want to make a table ‘irtf_hb’ if I do,
> irtf_hb = Table(names=irtf.colnames) 
> the table is initialized with all the right column names but the dtypes are all floats. However, I can’t do this,
> irtf_hb = Table(names=irtf.colnames, dtype=irtf.dtype)
> Because I get an error, “ValueError: dtype must be a list or None”. I haven’t had any luck with trying to change the type of irtf.dtype or using list comprehension to extract a list of dtypes. 
> Is there a simple way to use the dtypes of an existing table to initialize a new table?
> Thank you,
> Alexa
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://urldefense.proofpoint.com/v2/url?u=http-3A__mail.scipy.org_mailman_listinfo_astropy&d=AwIF-g&c=-dg2m7zWuuDZ0MUcV7Sdqw&r=AHkQ8HPUDwzl0x62ybAnwN_OEebPRGDtcjUPBcnLYw4&m=rGucwbRRBSwsQ4tj_W9Ic1p8QMfz7AiI-PqwLZDvry4&s=54VhWWCMNDv_liugJ2cksXWVx4hg1OgEDLTEQH_EOk8&e= 

More information about the AstroPy mailing list