<div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">arr.names</code> should have been <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">arr.dtype.names</code> in that <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">pack_last_axis</code> function</p>
<p style="margin:0px 0px 1.2em!important">Eric</p><p style="margin:0px 0px 1.2em!important"><br></p>
<div title="MDH:YGFyci5uYW1lc2Agc2hvdWxkIGhhdmUgYmVlbiBgYXJyLmR0eXBlLm5hbWVzYCBpbiB0aGF0IGBw
YWNrX2xhc3RfYXhpc2AgZnVuY3Rpb248ZGl2Pjxicj48L2Rpdj48ZGl2PkVyaWM8L2Rpdj4=" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, 26 Jan 2018 at 12:45 Chris Barker <<a href="mailto:chris.barker@noaa.gov">chris.barker@noaa.gov</a>> wrote:<br></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">On Fri, Jan 26, 2018 at 10:48 AM, Allan Haldane <span dir="ltr"><<a href="mailto:allanhaldane@gmail.com" target="_blank">allanhaldane@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="m_3322874899046307177gmail-HOEnZb"><div class="m_3322874899046307177gmail-h5">> What do folks think about a totuple() method — even before this I’ve<br>
> wanted that. But in this case, it seems particularly useful.</div></div></blockquote><div> </div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="m_3322874899046307177gmail-HOEnZb"><div class="m_3322874899046307177gmail-h5"><span style="color:rgb(34,34,34)">Two thoughts:</span><br></div></div></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
1. `totuple` makes most sense for 2d arrays. But what should it do for<br>
1d or 3+d arrays? I suppose it could make the last dimension a tuple, so<br>
1d arrays would give a list of tuples of size 1.<br></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"></blockquote><div><br></div><div>I was thinking it would be exactly like .tolist() but with tuples -- so you'd get tuples all the way down (or is that turtles?)</div><div><br></div><div>IN this use case, it would have saved me the generator expression:</div><div><br></div><div>(tuple(r) for r in arr)</div><div><br></div><div>not a huge deal, but it would be nice to not  have to write that, and to have the looping be in C with no intermediate array generation.</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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">2. structured array's .tolist() already returns a list of tuples. If we<br>
have a 2d structured array, would it add one more layer of tuples?</blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>no -- why? it would return a tuple of tuples instead.</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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"> That<br>
would raise an exception if read back in by `np.array` with the same dtype.<br></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Hmm -- indeed, if the top-level structure is a tuple, the array constructor gets confused:</div><div><br></div><div>This works fine -- as it should:</div><div>







<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><br></span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_3322874899046307177gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>84</b></span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">new_full = np.array(full.tolist(), full.dtype)</span></p>
<p class="m_3322874899046307177gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:15px"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p><p class="m_3322874899046307177gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:15px">But this does not:</p><p class="m_3322874899046307177gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:15px"><br></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_3322874899046307177gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>85</b></span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">new_full = np.array(</span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">tuple</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">(full.tolist()), full.dtype)</span></p></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>
<p class="m_3322874899046307177gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(195,55,32);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">---------------------------------------------------------------------------</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">ValueError</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="m_3322874899046307177gmail-Apple-converted-space">                                </span>Traceback (most recent call last)</span></p>
</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><p class="m_3322874899046307177gmail-p4" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><ipython-input-85-c305063184ff></span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> in </span><span class="m_3322874899046307177gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)"><module></span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">()</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">----> 1</span><span class="m_3322874899046307177gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)"> </span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">new_full </span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">=</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> np</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">.</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">array</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">tuple</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">full</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">.</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">tolist</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">()),</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> full</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">.</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">dtype</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)</span></p>
<p class="m_3322874899046307177gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:15px"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">ValueError</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">: could not assign tuple of length 4 to structure with 2 fields.</span></p></div><div><br></div><div>I was hoping it would dig down to the inner structures looking for a match to the dtype, rather than looking at the type of the top level. Oh well.</div><div><br></div><div>So yeah, not sure where you would go from tuple to list -- probably at the bottom level, but that may not always be unambiguous.</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><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">
These points make me think that instead of a `.totuple` method, this<br>
might be more suitable as a new function in np.lib.recfunctions.</blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I don't seem to have that module -- and I'm running 1.14.0 -- is this a new idea?</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> If the<br>
goal is to help manipulate structured arrays, that submodule is<br>
appropriate since it already has other functions do manipulate fields in<br>
similar ways. What about calling it `pack_last_axis`?<br>
<br>
def pack_last_axis(arr, names=None):<br>
    if arr.names:<br>
        return arr<br>
    names = names or ['f{}'.format(i) for i in range(arr.shape[-1])]<br>
    return arr.view([(n, arr.dtype) for n in names]).squeeze(-1)<br>
<br>
Then you could do:<br>
<br>
    >>> pack_last_axis(uv).tolist()<br>
<br>
to get a list of tuples.<br></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>not sure what idea is here -- in my example, I had a regular 2-d array, so no names:</div><div><br></div><div>







<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_3322874899046307177gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>90</b></span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">pack_last_axis(uv)</span></p>
<p class="m_3322874899046307177gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(195,55,32);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">---------------------------------------------------------------------------</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">AttributeError</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="m_3322874899046307177gmail-Apple-converted-space">                            </span>Traceback (most recent call last)</span></p>
<p class="m_3322874899046307177gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><ipython-input-90-a75ee44c8401></span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> in </span><span class="m_3322874899046307177gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)"><module></span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">()</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">----> 1</span><span class="m_3322874899046307177gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)"> </span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">pack_last_axis</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">uv</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)</span></p>
<p class="m_3322874899046307177gmail-p4" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:15px"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_3322874899046307177gmail-p3" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(52,188,38);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><ipython-input-89-cfbc76779d1f></span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> in </span><span class="m_3322874899046307177gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)">pack_last_axis</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(arr, names)</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)"><b><span class="m_3322874899046307177gmail-Apple-converted-space">      </span>1</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">def</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> pack_last_axis</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">arr</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">,</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> names</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">=</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">None</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">):</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">----> 2</span><span class="m_3322874899046307177gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)"> <span class="m_3322874899046307177gmail-Apple-converted-space">    </span></span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">if</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> arr</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">.</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">names</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">:</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)"><b><span class="m_3322874899046307177gmail-Apple-converted-space">      </span>3</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> <span class="m_3322874899046307177gmail-Apple-converted-space">        </span></span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">return</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> arr</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)"><b><span class="m_3322874899046307177gmail-Apple-converted-space">      </span>4</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> <span class="m_3322874899046307177gmail-Apple-converted-space">    </span>names </span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">=</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> names </span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">or</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">['f{}'.</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">format</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">i</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">for</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> i </span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">in</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> range</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">arr</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">.</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">shape</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">[-</span><span class="m_3322874899046307177gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)">1</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">])]</span></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)"><b><span class="m_3322874899046307177gmail-Apple-converted-space">      </span>5</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> <span class="m_3322874899046307177gmail-Apple-converted-space">    </span></span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">return</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> arr</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">.</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">view</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">([(</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">n</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">,</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> arr</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">.</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">dtype</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">for</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> n </span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,188,38)">in</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> names</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">]).</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">squeeze</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">(-</span><span class="m_3322874899046307177gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(51,187,200)">1</span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(82,48,225)">)</span></p>
<p class="m_3322874899046307177gmail-p4" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:15px"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(195,55,32)">AttributeError</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">: 'numpy.ndarray' object has no attribute 'names'</span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">So maybe you meants something like:</span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_3322874899046307177gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>95</b></span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: <b>def</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="m_3322874899046307177gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)">pack_last_axis</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">(arr, names=</span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">None</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">):</span></p><p class="m_3322874899046307177gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="m_3322874899046307177gmail-Apple-converted-space">    </span>...: </span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_3322874899046307177gmail-Apple-converted-space">    </span></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><b>try</b></span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">:</span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="m_3322874899046307177gmail-Apple-converted-space">    </span>...: </span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="m_3322874899046307177gmail-Apple-converted-space">        </span>arr.names</span></p><p class="m_3322874899046307177gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="m_3322874899046307177gmail-Apple-converted-space">    </span>...: </span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_3322874899046307177gmail-Apple-converted-space">        </span></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><b>return</b></span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> arr</span></p><p class="m_3322874899046307177gmail-p2" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="m_3322874899046307177gmail-Apple-converted-space">    </span>...: </span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="m_3322874899046307177gmail-Apple-converted-space">    </span></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><b>except</b></span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="m_3322874899046307177gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,119,117)"><b>AttributeError</b></span><span class="m_3322874899046307177gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">:</span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="m_3322874899046307177gmail-Apple-converted-space">    </span>...: </span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="m_3322874899046307177gmail-Apple-converted-space">        </span>names = names </span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>or</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> [</span><span class="m_3322874899046307177gmail-s8" style="font-variant-ligatures:no-common-ligatures;color:rgb(205,121,35)">'f{}'</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">.format(i) </span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> i </span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> </span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">range</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">(arr.shape[-</span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">1</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">])]</span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)">













</p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="m_3322874899046307177gmail-Apple-converted-space">    </span>...: </span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"><span class="m_3322874899046307177gmail-Apple-converted-space">        </span></span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>return</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> arr.view([(n, arr.dtype) </span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>for</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> n </span><span class="m_3322874899046307177gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures"> names]).squeeze(-</span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">1</span><span class="m_3322874899046307177gmail-s3" style="font-variant-ligatures:no-common-ligatures">)</span></p></div><div><br></div><div>which does work, but seems like a convoluted way to get tuples!</div><div><br></div><div>However, I didn't actually need tuples, I needed something I could pack into a stuctarray, and this does work, without the tolist:</div><div><br></div><div>







<p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures">full = np.array(</span><span class="m_3322874899046307177gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">zip</span><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures">(time, pack_last_axis(uv)), dtype=dt)</span></p><p class="m_3322874899046307177gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="m_3322874899046307177gmail-s1" style="font-variant-ligatures:no-common-ligatures"><br></span></p>So maybe that is the way to go.</div><div><br></div><div>I'm not sure I'd have thought to look for this function, but what can you do?</div><div><br></div><div>Thanks for your attention to this,</div><div><br></div><div>-CHB</div></div><div class="gmail_extra"><br></div>-- <br><div class="m_3322874899046307177gmail_signature"></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="m_3322874899046307177gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="m_3322874899046307177gmail_signature">NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div>