home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 350818717

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/1773#issuecomment-350818717 https://api.github.com/repos/pydata/xarray/issues/1773 350818717 MDEyOklzc3VlQ29tbWVudDM1MDgxODcxNw== 11997114 2017-12-11T18:46:12Z 2017-12-11T18:46:12Z NONE

@fmaussion Thank you, that's going to help with a lot of my problems for my computational work

@shoyer I am looking at the docs for xarray.broadcast() and xarray.apply_ufunc . below is my attempt at trying what you said (though I am most likely missing something) using the broadcast. But broadcast only act's on two arrays at a time. Below is what I tried from what I think your saying (example would clarify this quickly)

``` import numpy as np import xarray as xr

DomainSpaceTimeSize = 5 # using cartesian 4D SpaceTimeDensity = [100, 5] # 100 divisions in space 5 in time

x_coord = np.linspace(-DomainSpaceTimeSize, +DomainSpaceTimeSize, SpaceTimeDensity[0]) y_coord = np.linspace(-DomainSpaceTimeSize, +DomainSpaceTimeSize, SpaceTimeDensity[0]) z_coord = np.linspace(-DomainSpaceTimeSize, +DomainSpaceTimeSize, SpaceTimeDensity[0]) t_coord = np.linspace(0, +DomainSpaceTimeSize, SpaceTimeDensity[1])

dx=xr.DataArray(x_coord, dims='x') dy=xr.DataArray(y_coord, dims='y') dz=xr.DataArray(z_coord, dims='z') dt=xr.DataArray(t_coord, dims='t')

ds, =xr.broadcast(dx, dy) ds, =xr.broadcast(ds, dz) ds, _=xr.broadcast(ds, dt) ds `` @shoyer your reply on usingxarray.apply_ufuncis what I am looking for when I got broadcasting issues such as this one from using sympy'slambdfy` (for sake of argument lets stay out of the sympy lambdfy rabit hole and say this could have come from anywhere) on a vector function

``` from sympy import * init_printing()

x, y, z, t=symbols('x, y, z, t') xDirVec=Matrix([1,0,0])

vector_func=cos(1x+2y+3z-4t)*xDirVec vector_func

vector_funcN=lambdify((x, y, z, t), vector_func, dummify=False)

data point test

vector_funcN(1,1,1,1)

target compersion

vector_func_npRef=lambda x, y, z, t: np.array([np.cos(1x+2y+3z-4t), 0, 0])

point test

vector_funcN(1,1,1,1)

point test match test: pass

np_SpaceResult=vector_func_npRef(np.meshgrid(x_coord, y_coord, z_coord, t_coord)).shape sp_SpaceResult=vector_funcN(np.meshgrid(x_coord, y_coord, z_coord, t_coord)).shape

and as can be seen the two shapes dont match

`` so then how would I usexr.apply_ufuncon thelambdfyfunctionvector_funcN`. Again quick example would be much appreciated

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  280899335
Powered by Datasette · Queries took 0.831ms · About: xarray-datasette