News for hackers. Stuff that matters.
Re:Loops in Python – Comparison and Performance by silvester23 on Thursday August 08, 2019 @10:09AM (#20644712)
I think it's especially odd that they only take the time for the actual addition of the arrays into account.

Initializing the arrays already takes way longer than adding them in a list comprehension. So if you're doing one-off additions of lists, converting them to np arrays is most likely not worth it.

Here are a couple of quick results I got with the same data setup as in the article:

  List comprehension with zip:   4.748612998810131e-05s
  Just building the np.arrays:   0.00013617933000205086s
  Building and adding np.arrays: 0.00013746836000791518s

There are no comments on this comment yet.