Skip to content Skip to sidebar Skip to footer

How To Covert Np.ndarray Into Astropy.coordinates.angle Class?

What is the quickest/most efficient way to convert a np.ndarray (importing numpy as np) into the astropy.coordinates.Angle class? I am having trouble keeping it as np.ndarray becau

Solution 1:

What exactly is your intention? np.asarray is quite ambiguous. If you are dealing with np.ndarray it is quite easy:

from astropy.coordinates import Angle
import astropy.units as u
import numpy as np

angles = np.array([100,200,300,400])
angles_quantity = a * u.degree # Could also be u.radian, u.arcmin, etc.
Angle(angles_quantity).wrap_at('360d')

But I'm not really sure if that solves your problem.

Converting such an Angle object back to a simple np.ndarray can be done with the .value attribute:

Angle(angles_quantity).wrap_at('360d').value # This returns a simple ndarray again.

Post a Comment for "How To Covert Np.ndarray Into Astropy.coordinates.angle Class?"