I have first variable h having dimension (111,141) another variable cs_w having dimension (51,). Basically my data is ROMS history output data. Now I want to multiply h with cs_w and the final result should be of dimension (51,111,141). Here I got stuck and unabble to proceed. below is my code
import numpy as np
import matplotlib.pyplot as plt
import netCDF4 as nc
f_in = nc.Dataset('ocean_his_0010.nc', "r")
h = f_in.variables['h']
cs_w = f_in.variables['Cs_w']
z=[[],[],[]]
for i in range(len(h[0])):
for j in range(len(h[1])):
for k in range(len(cs_w)):
z[i][j][k] = h[i][j]*cs_w[k]
Here is the description of the two variable which I want to use.
Out[88]: float64 Cs_w(s_w) long_name: S-coordinate stretching curves at W-points valid_min: -1.0 valid_max: 0.0 field: Cs_w, scalar unlimited dimensions: current shape = (51,) filling on, default _FillValue of 9.969209968386869e+36 used
h Out[89]: float64 h(eta_rho, xi_rho) long_name: bathymetry at RHO-points units: meter grid: grid location: face coordinates: lon_rho lat_rho field: bath, scalar unlimited dimensions: current shape = (111, 141) filling on, default _FillValue of 9.969209968386869e+36 used
Below is the ncdump ocean_his_0010.nc
netcdf ocean_his_0010 {
dimensions:
xi_rho = 141 ;
xi_u = 140 ;
xi_v = 141 ;
xi_psi = 140 ;
eta_rho = 111 ;
eta_u = 111 ;
eta_v = 110 ;
eta_psi = 110 ;
N = 50 ;
s_rho = 50 ;
s_w = 51 ;
tracer = 2 ;
boundary = 4 ;
ocean_time = UNLIMITED ; // (360 currently)
double Cs_w(s_w) ;
Cs_w:long_name = "S-coordinate stretching curves at W-points" ;
Cs_w:valid_min = -1. ;
Cs_w:valid_max = 0. ;
Cs_w:field = "Cs_w, scalar" ;
double h(eta_rho, xi_rho) ;
h:long_name = "bathymetry at RHO-points" ;
h:units = "meter" ;
h:grid = "grid" ;
h:location = "face" ;
h:coordinates = "lon_rho lat_rho" ;
h:field = "bath, scalar" ;