{"action":"closed","issue":{"url":"https://api.github.com/repos/dask/dask/issues/2412","repository_url":"https://api.github.com/repos/dask/dask","labels_url":"https://api.github.com/repos/dask/dask/issues/2412/labels{/name}","comments_url":"https://api.github.com/repos/dask/dask/issues/2412/comments","events_url":"https://api.github.com/repos/dask/dask/issues/2412/events","html_url":"https://github.com/dask/dask/issues/2412","id":233639620,"node_id":"MDU6SXNzdWUyMzM2Mzk2MjA=","number":2412,"title":"array getitem with another array and broadcasting","user":{"login":"TomAugspurger","id":1312546,"node_id":"MDQ6VXNlcjEzMTI1NDY=","avatar_url":"https://avatars3.githubusercontent.com/u/1312546?v=4","gravatar_id":"","url":"https://api.github.com/users/TomAugspurger","html_url":"https://github.com/TomAugspurger","followers_url":"https://api.github.com/users/TomAugspurger/followers","following_url":"https://api.github.com/users/TomAugspurger/following{/other_user}","gists_url":"https://api.github.com/users/TomAugspurger/gists{/gist_id}","starred_url":"https://api.github.com/users/TomAugspurger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomAugspurger/subscriptions","organizations_url":"https://api.github.com/users/TomAugspurger/orgs","repos_url":"https://api.github.com/users/TomAugspurger/repos","events_url":"https://api.github.com/users/TomAugspurger/events{/privacy}","received_events_url":"https://api.github.com/users/TomAugspurger/received_events","type":"User","site_admin":false},"labels":[{"id":242862305,"node_id":"MDU6TGFiZWwyNDI4NjIzMDU=","url":"https://api.github.com/repos/dask/dask/labels/array","name":"array","color":"006b75","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2017-06-05T16:20:55Z","updated_at":"2018-06-29T15:49:56Z","closed_at":"2018-06-29T15:49:56Z","author_association":"MEMBER","body":"An example\r\n\r\n```python\r\n>>> x = np.arange(12).reshape(4, 3)\r\n>>> y = np.array([1, 1, 2, 3])\r\n>>> dx = da.from_array(x, chunks=2)\r\n>>> dy = da.from_array(y, chunks=2)\r\n>>> x[y == 1]  # NumPy\r\narray([[0, 1, 2],\r\n       [3, 4, 5]])\r\nIn [43]: dx[dy == 1]\r\n```\r\n```pytb\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-43-9a0439f73673> in <module>()\r\n----> 1 dx[dy == 1]\r\n\r\n/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/array/core.py in __getitem__(self, index)\r\n   1196         # Slicing\r\n   1197         if isinstance(index, Array):\r\n-> 1198             return slice_with_dask_array(self, index)\r\n   1199\r\n   1200         if not isinstance(index, tuple):\r\n\r\n/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/array/core.py in slice_with_dask_array(x, index)\r\n   3868\r\n   3869 def slice_with_dask_array(x, index):\r\n-> 3870     y = elemwise(getitem, x, index, dtype=x.dtype)\r\n   3871\r\n   3872     name = 'getitem-' + tokenize(x, index)\r\n\r\n/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/array/core.py in elemwise(op, *args, **kwargs)\r\n   2624     shapes = [getattr(arg, 'shape', ()) for arg in args]\r\n   2625     shapes = [s if isinstance(s, Iterable) else () for s in shapes]\r\n-> 2626     out_ndim = len(broadcast_shapes(*shapes))   # Raises ValueError if dimensions mismatch\r\n   2627     expr_inds = tuple(range(out_ndim))[::-1]\r\n   2628\r\n\r\n/Users/taugspurger/Envs/dask-dev/lib/python3.6/site-packages/dask/dask/array/core.py in broadcast_shapes(*shapes)\r\n   2597         if any(i != -1 and i != 1 and i != dim and not np.isnan(i) for i in sizes):\r\n   2598             raise ValueError(\"operands could not be broadcast together with \"\r\n-> 2599                              \"shapes {0}\".format(' '.join(map(str, shapes))))\r\n   2600         out.append(dim)\r\n   2601     return tuple(reversed(out))\r\n\r\nValueError: operands could not be broadcast together with shapes (4, 3) (4,)\r\n ```\r\n\r\nA solution is for the user to manually reshape to `y` to a 2-d array, with length 1 on the second dimension. Then the broadcasting lines up. I think we want to follow NumPy here (if possible?)"}}
{"actor":{"display_login":"TomAugspurger"}}