This question already has an answer here:
- foggy on asterisk in python 3 answers
In some MachineLearning tutorial I discovered the following code:
trX = np.linspace(-1, 1, 101)
trY = 2 * trX + np.random.randn(*trX.shape) * 0.33
^
|___ what does this do?
At first I thought this is a mistake but the code is working perfectly and if I delete the *
in *trX.shape
the code generates errors. However, I am unable to figure out what exactly this operator does to the parameter trX.shape
. If I try *someArray.shape
in IPython it always throws a syntax error.
Is it some special "trick operator" somehow unpacking the shape and converting it to an integer? (since random.randn awaits an integer)
Aucun commentaire:
Enregistrer un commentaire