0

I am a python newbie and I keep seeing code like:

import numpy as np
rng = np.random.RandomState(4)

# generate some random data to train on
get_rand = lambda *shape: np.asarray(rng.rand(*shape) > 0.5, dtype='float32')

Is * referring a pointer ? Please help me in understanding what does * do here (I know C so I guess this looks like a pointer, but it can't be).

Rafael
  • 651
  • 13
  • 30
  • Not clear from the reffered question, what is the code doing here, why need a * ...answer will help a lot of people. thanks. – Rafael Oct 14 '16 at 07:01
  • It means that all positional arguments that are passed to be the function defined by the lambda are placed as elements in a tuple named shape. rng.rand(*shape) does the opposite, it takes all elements from the tuple shape and passes them as positional arguments to rng.rand. – RemcoGerlich Oct 14 '16 at 07:03
  • @RemcoGerlich thanks a lot, python is a lot more high level than C. Even better than C++. – Rafael Oct 14 '16 at 07:08

0 Answers0