[Numpy-discussion] reshaping arrays
Benjamin Root
ben.root at ou.edu
Mon Mar 4 09:10:54 EST 2013
On Sat, Mar 2, 2013 at 11:35 PM, Sudheer Joseph <sudheer.joseph at yahoo.com>wrote:
> Hi Brad,
> I am not getting the attribute reshape for the array, are
> you having a different version of numpy than mine?
>
> I have
> In [55]: np.__version__
> Out[55]: '1.7.0'
> and detail of the shape
>
> details of variable
>
> In [57]: ssh??
> Type: NetCDFVariable
> String Form:<NetCDFVariable object at 0x492d3d8>
> Namespace: Interactive
> Length: 75
> Docstring: NetCDF Variable
>
> In [58]: ssh.shape
> Out[58]: (75, 140, 180)
>
> ssh??
> Type: NetCDFVariable
> String Form:<NetCDFVariable object at 0x492d3d8>
> Namespace: Interactive
> Length: 75
> Docstring: NetCDF Variable
>
> In [66]: ssh.shape
> Out[66]: (75, 140, 180)
>
> In [67]: ssh.reshape(75,140*180)
> ---------------------------------------------------------------------------
> AttributeError Traceback (most recent call last)
> /home/sjo/RAMA_20120807/adcp/<ipython-input-67-1a21dae1d18d> in <module>()
> ----> 1 ssh.reshape(75,140*180)
>
> AttributeError: reshape
>
>
>
Ah, you have a NetCDF variable, which in many ways purposefully looks like
a NumPy array, but isn't. Just keep in mind that a NetCDF variable is
merely a way to have the data available without actually reading it in
until you need it. If you do:
ssh_data = ssh[:]
Then the NetCDF variable will read all the data in the file and return it
as a numpy array that can be manipulated as you wish.
I hope that helps!
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130304/438d0d72/attachment.html>
More information about the NumPy-Discussion
mailing list