<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 23, 2017 at 12:10 PM, Adam Ginsburg <span dir="ltr"><<a href="mailto:adam.g.ginsburg@gmail.com" target="_blank">adam.g.ginsburg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF">
    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.<span class="m_7466198376326171714gmail-"><br><br></span></div></blockquote><div><br></div></span><div>I'm not sure this is what you meant to ask, but I'll answer:</div><div><br></div><div>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:<div><br></div><div>data = fits.getdata(filename)</div><div>data[:, :, None, None]</div></div></div></div></div></blockquote><div><br></div><div>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.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><div><br></div></div><div class="m_7466198376326171714gmail_signature"><div dir="ltr"><div><div dir="ltr"></div></div></div></div>
</div></div>
<br>______________________________<wbr>_________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@python.org">AstroPy@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/astropy" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/astropy</a><br>
<br></blockquote></div><br></div></div>