0

I saw the below function in one place:

import numpy as np
def cube(data_set):
    new_data_set=np.nditer([data_set, None])
    for a,b in new_data_set:
        b[...]=a*a*a
    return new_data_set.operands[1]
Data_set=np.arange(3)
print(cube(Data_set)) 

What I am not able to understand is the use the part b[...]. What are the 3 dosts exactly doing here or in general?

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
  • 3
    It is equivalent to `b.__getitem__(Ellipsis)` and what it exactly does depends on the implementation of `b`. See also: https://docs.python.org/3/library/constants.html#Ellipsis – Klaus D. Oct 28 '20 at 07:53
  • 2
    It's like `b[:]=...``but more general. And required by this use of `nditer`. Don't spend too much time on this bit of code. Beginners shouldn't be using `nditer`. – hpaulj Oct 28 '20 at 08:29

0 Answers0