0
data = [-1,-5,1,5,3]
soft_max = softmax(data)
print(('softmax(data) = [' + 4*'{:.4e} ' + '{:.4e}').format(*soft_max))
soft_max_sum = np.sum(soft_max)
print('sum(softmax) = {:.3f}'.format(soft_max_sum))

1) what does the star * in 4* and *soft_max mean?

2) What does this part do below?

4*'{:.4e} ' + '{:.4e}'
marlon
  • 6,029
  • 8
  • 42
  • 76
  • Possible duplicate of [What does \*\* (double star/asterisk) and \* (star/asterisk) do for parameters?](https://stackoverflow.com/q/36901/1092820) – Ruzihm Nov 08 '19 at 21:29
  • 1
    @marlon, those are two _different_ uses of the star! The first one concatenates 4 copies of the string that follows, for the second see the link given by Ruzihm. – alexis Nov 08 '19 at 21:32
  • ...indeed, the one that's a correct duplicate is [Multiplying a string with a number in Python](https://stackoverflow.com/questions/3536996/multiplying-a-string-with-a-number-in-python). – Charles Duffy Nov 08 '19 at 21:41
  • The first star is part of the expression `4*'{:.4e} '`. (You can't take just the `4*` here.) The second star is part of the function call `format(*soft_max)`. – Code-Apprentice Nov 08 '19 at 21:44
  • Ahh, you're right; I'll add the other question back to the duplicate list. – Charles Duffy Nov 08 '19 at 21:45
  • @Code-Apprentice. Can you give a full answer? – marlon Nov 08 '19 at 22:34
  • @marlon Read the links at the top of this page. They explain the two different uses of `*`. – Code-Apprentice Nov 08 '19 at 22:52

0 Answers0