[AstroPy] astropy.io.fits won't allow me to modify the NAXIS keywords

Nathan Goldbaum nathan12343 at gmail.com
Mon Oct 23 11:14:21 EDT 2017


On Mon, Oct 23, 2017 at 12:10 PM, Adam Ginsburg <adam.g.ginsburg at gmail.com>
wrote:

>
>
>> Do you know what would be the best syntax to add a trailing dimension
>> from a 2D image? I mean, in a clever way without doubling the memory
>> consumption.
>>
>>
> I'm not sure this is what you meant to ask, but I'll answer:
>
> The simplest way to expand an array's dimensions without expanding its
> memory consumption is with an indexing trick.  This will turn a 2D array
> (assuming the original file was 2D) into a 4D array with dimensions 3 and 4
> having size 1:
>
> data = fits.getdata(filename)
> data[:, :, None, None]
>

One can also use np.newaxis, which is just an alias to None. It's a tiny
bit more readable for people who aren't aware of how None works in numpy's
indexing system.


>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20171023/fc405cfd/attachment-0001.html>


More information about the AstroPy mailing list