Stream: python-questions

Topic: data array multiplication unexpectedly zeroing dimensions


view this post on Zulip Danica Lombardozzi (Apr 02 2020 at 23:14):

I am running into a problem when multiplying two data arrays. In particular, the multiplication is collapsing one of the variable dimensions. The code is a simple multiplication of two variables that are both

#sub_gpp: xarray.DataArray (years: 319, month: 12, pft: 64, lat: 192, lon: 288)
#cropwtsmask: xarray.DataArray (years: 319, pft: 64, lat: 192, lon: 288)

gridded_wts = sub_gpp * cropwtsmask

The 'gridded_wts' variable keeps all the dimensions the same size except the 'pft' dimension:
gridded_wts: xarray.DataArray (years: 319, month: 12, pft: 0, lat: 192, lon: 288)

Any idea why this is happening and what I might be doing incorrectly? Help is very much appreciated!

view this post on Zulip Anna-Lena Deppenmeier (Apr 02 2020 at 23:21):

I am running into a problem when multiplying two data arrays. In particular, the multiplication is collapsing one of the variable dimensions. The code is a simple multiplication of two variables that are both

#sub_gpp: xarray.DataArray (years: 319, month: 12, pft: 64, lat: 192, lon: 288)
#cropwtsmask: xarray.DataArray (years: 319, pft: 64, lat: 192, lon: 288)

gridded_wts = sub_gpp * cropwtsmask

The 'gridded_wts' variable keeps all the dimensions the same size except the 'pft' dimension:
gridded_wts: xarray.DataArray (years: 319, month: 12, pft: 0, lat: 192, lon: 288)

Any idea why this is happening and what I might be doing incorrectly? Help is very much appreciated!

Hi Danica, have you checked that your pft dimension has the same values? If you were to multiply to columns with each dimension depth:15, but one of them would have coordinates [1m, 2m, 3m..] and the other [1.5m, 2.5m, 3.5m] it would not multiply them.

view this post on Zulip Danica Lombardozzi (Apr 10 2020 at 19:21):

I am running into a problem when multiplying two data arrays. In particular, the multiplication is collapsing one of the variable dimensions. The code is a simple multiplication of two variables that are both

#sub_gpp: xarray.DataArray (years: 319, month: 12, pft: 64, lat: 192, lon: 288)
#cropwtsmask: xarray.DataArray (years: 319, pft: 64, lat: 192, lon: 288)

gridded_wts = sub_gpp * cropwtsmask

The 'gridded_wts' variable keeps all the dimensions the same size except the 'pft' dimension:
gridded_wts: xarray.DataArray (years: 319, month: 12, pft: 0, lat: 192, lon: 288)

Any idea why this is happening and what I might be doing incorrectly? Help is very much appreciated!

Hi Danica, have you checked that your pft dimension has the same values? If you were to multiply to columns with each dimension depth:15, but one of them would have coordinates [1m, 2m, 3m..] and the other [1.5m, 2.5m, 3.5m] it would not multiply them.

Thanks for this tip! I thought the dimensions were identical, but they in fact were not. Setting them equal fixed the problem!


Last updated: Jan 30 2022 at 12:01 UTC