plasma-python icon indicating copy to clipboard operation
plasma-python copied to clipboard

Use .T instead of np.transpose() for better performance and readability

Open SaFE-APIOpt opened this issue 10 months ago • 0 comments

https://github.com/PPPLDeepLearning/plasma-python/blob/b13dbed1883730d971dfe87fc1bc44e368840083/data/gadata.py#L77 In the following code: if numpy.ndim(self.ydata) == 2: self.ydata = numpy.transpose(self.ydata) it's better to replace np.transpose() with the shorthand .T: if numpy.ndim(self.ydata) == 2: self.ydata = self.ydata.T Both versions produce the same result for 2D arrays, but .T is more efficient as it directly accesses the array’s transpose property without invoking a function call. It also improves code clarity and conforms to standard NumPy coding practices.

SaFE-APIOpt avatar Mar 18 '25 08:03 SaFE-APIOpt