[ SciPy v1.12.0 Manual  ](../../index.html)

  * [ Installing ](https://scipy.org/install/)
  * [ User Guide ](../../tutorial/index.html)
  * [ API reference ](../index.html)
  * [ Building from source ](../../building/index.html)
  * [ Development ](../../dev/index.html)
  * [ Release notes ](../../release.html)

__ __ __

1.12.0

  * [ __ GitHub  ](https://github.com/scipy/scipy "GitHub")
  * [ __ Twitter  ](https://twitter.com/SciPy_team "Twitter")

__

  * [ scipy ](../main_namespace.html)
  * [ scipy.cluster ](../cluster.html)
  * [ scipy.constants ](../constants.html)
  * [ scipy.datasets ](../datasets.html)
  * [ scipy.fft ](../fft.html)
  * [ scipy.fftpack ](../fftpack.html)
  * [ scipy.integrate ](../integrate.html)
  * [ scipy.interpolate ](../interpolate.html)
  * [ scipy.io ](../io.html)
  * [ scipy.linalg ](../linalg.html)
  * [ scipy.misc ](../misc.html)
  * [ scipy.ndimage ](../ndimage.html)
  * [ scipy.odr ](../odr.html)
  * [ scipy.optimize ](../optimize.html)
  * [ scipy.signal ](../signal.html)
  * [ scipy.sparse ](../sparse.html)
  * [ scipy.spatial ](../spatial.html)
  * [ scipy.special ](../special.html)
  * [ scipy.stats ](../stats.html)

__ On this page

  * ` netcdf_variable  `

#  scipy.io.netcdf_variable  #

_ class  _ scipy.io.  netcdf_variable  (  _ data  _ , _ typecode  _ , _ size
_ , _ shape  _ , _ dimensions  _ , _ attributes  =  None  _ , _ maskandscale
=  False  _ )  [ [source]
](https://github.com/scipy/scipy/blob/v1.12.0/scipy/io/_netcdf.py#L808-L1091)
#

    

A data object for netcdf files.

` netcdf_variable  ` objects are constructed by calling the method [ `
netcdf_file.createVariable  `
](scipy.io.netcdf_file.createVariable.html#scipy.io.netcdf_file.createVariable
"scipy.io.netcdf_file.createVariable") on the [ ` netcdf_file  `
](scipy.io.netcdf_file.html#scipy.io.netcdf_file "scipy.io.netcdf_file")
object.  ` netcdf_variable  ` objects behave much like array objects defined
in numpy, except that their data resides in a file. Data is read by indexing
and written by assigning to an indexed subset; the entire array can be
accessed by the index ` [:]  ` or (for scalars) by using the methods [ `
getValue  `
](scipy.io.netcdf_variable.getValue.html#scipy.io.netcdf_variable.getValue
"scipy.io.netcdf_variable.getValue") and [ ` assignValue  `
](scipy.io.netcdf_variable.assignValue.html#scipy.io.netcdf_variable.assignValue
"scipy.io.netcdf_variable.assignValue") .  ` netcdf_variable  ` objects also
have attribute [ ` shape  `
](scipy.io.netcdf_variable.shape.html#scipy.io.netcdf_variable.shape
"scipy.io.netcdf_variable.shape") with the same meaning as for arrays, but the
shape cannot be modified. There is another read-only attribute _dimensions_ ,
whose value is the tuple of dimension names.

All other attributes correspond to variable attributes defined in the NetCDF
file. Variable attributes are created by assigning to an attribute of the  `
netcdf_variable  ` object.

Parameters  :

    

**data** array_like

    

The data array that holds the values for the variable. Typically, this is
initialized as empty, but with the proper shape.

**typecode** dtype character code

    

Desired data-type for the data array.

**size** int

    

Desired element size for the data array.

**shape** sequence of ints

    

The shape of the array. This should match the lengths of the variableâs
dimensions.

**dimensions** sequence of strings

    

The names of the dimensions used by the variable. Must be in the same order of
the dimension lengths given by [ ` shape  `
](scipy.io.netcdf_variable.shape.html#scipy.io.netcdf_variable.shape
"scipy.io.netcdf_variable.shape") .

**attributes** dict, optional

    

Attribute values (any type) keyed by string names. These attributes become
attributes for the netcdf_variable object.

**maskandscale** bool, optional

    

Whether to automatically scale and/or mask data based on attributes. Default
is False.

See also

[ ` isrec  `
](scipy.io.netcdf_variable.isr