3 ms·
Not only now you are employing a foreign data type (numpy array) that requires separate learning independent (potentially confusing) to your existing Python kno
by hzhou321 9y ago
Not only now you are employing a foreign data type (numpy array) that requires separate learning independent (potentially confusing) to your existing Python knowledge, you also need mentally differentiate:
X = X + 2.0 * Y
X = X + 2 * Y
X += 2 * Y
X += Y; X += Y
, all irrelevant to your semantic logic.
Why not realizing that it is much more straight forward to directly do that in C? It is only a bit more to type but a much simpler mental load to understand (and maintain in the long run). If performance is at stake, spell it out in C (with x86 intrinsics if necessary) and put them into the semantics of your code.
Concerned with performance (in ms order) in Python is ill.
- pwang 9y agoWhen you use numpy, you're not one semicolon away from a segfault.
- cs702 9y agoThere's no need to mentally differentiate between all those approaches when writing code with Python's scientific stack. In practice, code is initially written with relatively little regard for how it affects the performance of Numpy and other libraries like it, and then, afterwards, and only if necessary, these techniques are used to optimize those lines of code that prove critical to performance, typically only a small fraction of all lines. However, if you're working on a project for which every line of code is performance-critical, then I would agree with you, Python would not be a good choice for that.