Skip to content

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

@SaFE-APIOpt

Description

@SaFE-APIOpt

self.ydata = numpy.transpose(self.ydata)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions