0

I'm wondering what * mean in this context. I've looked in the documentation too, but I'm still not too sure what it means. I've attached some code below for context.

(As an aside, I've also seen this used PyTorch tensors' .view() or .reshape_() method. Wondering if this is the same meaning.)

documentation: https://docs.scipy.org/doc/numpy/reference/generated/numpy.multiply.html

def one_hot_encode(arr, n_labels):

    one_hot = np.zeros((np.multiply(*arr.shape), n_labels), dtype=np.float32)

    one_hot[np.arange(one_hot.shape[0]), arr.flatten()] = 1.

    one_hot = one_hot.reshape((*arr.shape, n_labels))

    return one_hot
Fudge
  • 43
  • 6
  • ...wow, there's a lot of things this could be a duplicate of. – Nic Jul 02 '19 at 17:07
  • 2
    ^ Admittedly it is hard to search for – Nick T Jul 02 '19 at 17:07
  • Yes. Thanks, either ways, I'll read those. – Fudge Jul 02 '19 at 17:07
  • 4
    In this context it means, expand the `arr.shape` tuple into the two arguments that `np.multiply` takes. In other words, `np.multiply(arr.shape[0], arr.shape[1])`, or equivalently `arr.shape[0]*arr.shape[1]`. I think `np.prod(x.shape)` is a better expression. – hpaulj Jul 02 '19 at 17:22

0 Answers0