[Numpy-discussion] structured array from ordinary array

Pierre GM pgmdevlist@gmail....
Sun Dec 13 20:24:17 CST 2009


On Dec 13, 2009, at 8:54 PM, Ernest Adrogué wrote:
> Hi,
> 
> How does one generate a structured array from a normal
> array?
> 
> I use the 'view' method, but this way I get a superfluous
> dimension that I do not want. Example:
> 
> In [619]: a = np.array([[1,2,3],[1,2,3],[1,2,4]],int)
> 
> In [620]: struct = np.dtype([('a',int),('b',int),('c',int)])
> 
> In [621]: a.view(struct)
...

> I'd like the last array to have shape (3,).
> What am I doing wrong??


Put a .squeeze() after your view()


More information about the NumPy-Discussion mailing list