title: Convert a numpy dataset to netCDF
body: <p>I have a numpy array in python with size (16,250,186) representing time, latitude and longitude.</p>
  
  <p>I want to convert it to a netCDF file so that I can read the data easily with co-ordinates in future.</p>
  
  <p>My numpy array looks like this</p>
  
  <pre class="lang-py prettyprint-override"><code>RZS = np.load("/home/chandra/Data/rootzone_CHIRPS_era5_2003-2015_daily-analysis_annual-result.npy")
  RZS.shape
  
  Output: (16, 250, 186)
  </code></pre>
  
  <p>As you can see my above numpy array represents annual values for 16 years.</p>
  
  <pre class="lang-py prettyprint-override"><code>chirps_precip =xarray.open_mfdataset("/home/chandra/Data/CHIRPS/chirps-v2.0.2000.days_p25.nc")
  precip = chirps_precip.precip.sel(latitude = slice(-50,12.5), longitude = slice(-81.25,-34.75))
  precip[0,:,:]
  
  Output:
  &lt;xarray.DataArray 'precip' (latitude: 250, longitude: 186)&gt;
  dask.array&lt;shape=(250, 186), dtype=float32, chunksize=(250, 186)&gt;
  Coordinates:
    * latitude   (latitude) float32 -49.875 -49.625 -49.375 ... 12.125 12.375
    * longitude  (longitude) float32 -81.125 -80.875 -80.625 ... -35.125 -34.875
      time       datetime64[ns] 2000-01-01
  Attributes:
      units:               mm/day
      standard_name:       convective precipitation rate
      long_name:           Climate Hazards group InfraRed Precipitation with St...
      time_step:           day
      geostatial_lat_min:  -50.0
      geostatial_lat_max:  50.0
      geostatial_lon_min:  -180.0
      geostatial_lon_max:  180.0
  </code></pre>
  
  <p>These are the co-ordinates of the <code>chirps_precip</code> dataset that I want my numpy array <code>RZS</code> to have with years (as 2000, 2001, .....2015) on the timestep</p>
  
  <p>I have tried some methods like</p>
  
  <pre><code># from xarray
  array = xarray.DataArray(RZS, latitude = 'precip.latitude')
  
  #from netCDF
  Dataset.createVariable('rootzone storage cap', np.float32, ('time','lat','lon'))
  </code></pre>
  
  <p>But I am not able to do anything. I also tried to copy <code>attrs</code> and <code>coords</code> but that also didn't work.
  It seems like I am doing this the wrong way. Can anyone suggest what am I missing.</p>
  
  <p>I want my numpy array to have the same co-ordinate as the netcdf file, but with a modified <code>time</code> attribute to years.</p>