2

I'm trying to change the slice in Dask array row-wise and col-wise way:

from dask import array as da
A = da.from_array(np.zeros((3,3)))
A[[0,1,2], 0] = [1,2,3]
A.compute()

And I've got:

array([[1., 0., 0.],
       [2., 0., 0.],
       [3., 0., 0.]])

But in row-wise way:

A = da.from_array(np.zeros((3,3)))
A[0,[0,1,2]] = [1,2,3]
A.compute()

TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

Do You where the problem is? Or any other method to do this kind of assignment?

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
  • I think your two code snippets are the same? – Michael Delgado Mar 25 '22 at 22:21
  • I do see this different behavior though for `A[[0,1,2], 0] = [1,2,3]` getting your first result and your posted code giving the error – Michael Delgado Mar 25 '22 at 22:24
  • just reproduced this on `2022.01.0` and `2022.03.0` (latest) – Michael Delgado Mar 25 '22 at 22:35
  • I just edited your example to correct the duplicated snippet issue. this could be a live bug in dask. quickly looking through the open issues & PRs I don't see anything covering this. I do see that dask's `__setitem__` got a major refactor last year (see [issue #7392](https://github.com/dask/dask/issues/7392) and [PR #7393](https://github.com/dask/dask/pull/7393)). I think you could file an issue with this and see if it's known or is a new bug. – Michael Delgado Mar 25 '22 at 22:39
  • 1
    also, when asking about errors, please always include the [full traceback](//realpython.com/python-traceback) - they include a ton of useful detail about where the bug happened and how that flows through the code – Michael Delgado Mar 25 '22 at 22:41
  • I agree with @MichaelDelgado that this might be a bug, I'd encourage you to [open an issue for this](https://github.com/dask/dask/issues/new?assignees=&labels=Type%3ABug%2CType%3ANeeds+Triage&template=bug-report.md). :) – pavithraes Mar 30 '22 at 14:48

1 Answers1

0

Since this may be a bug, here are some workarounds to do the same operation:

  • A[0:1, [0,1,2]] = [1,2,3]
  • A[0] = [1,2,3]

Ref: https://docs.dask.org/en/stable/array-assignment.html

pavithraes
  • 724
  • 5
  • 9