Converting Astropy.table.columns To A Numpy Array
Solution 1:
An astropy Table Column object can be converted to a numpy array using the data
attribute:
In [7]: c = Column([1, 2, 3])
In [8]: c.data
Out[8]: array([1, 2, 3])
You can also convert an entire table to a numpy structured array with the as_array()
Table method (e.g. data.as_array()
in your example).
BTW I think the actual problem is not about astropy Column
but your numpy array creation statement. It should probably be:
arr = np.array([data['ra'], data['dec']])
This works with Column
objects.
Solution 2:
The signature of numpy.array
is numpy.array(object, dtype=None,)
Hence, when calling np.array([data['ra']], [data['dec']])
, [data['ra']]
is the object to convert to a numpy array, and [data['dec']]
is the data type, which is not understood (as the error says).
It's not actually clear from the question what you are trying to achieve instead - possibly something like
points = np.array([data['ra'], data['dec']])
Solution 3:
Keep in mind, though, that if you actiually want is to plot points you don't need to convert to arrays. The following will work just fine:
from matplotlib import pyplot as plt
plt.scatter(data['ra'], data['dec'])
With no need to do any conversion to arrays.
Post a Comment for "Converting Astropy.table.columns To A Numpy Array"