Skip to content

Avoid redundant np.array(np.transpose(...)) – use .T instead #1

Description

@SaFE-APIOpt

tfmatrix = numpy.array(numpy.transpose(tfmatrix.collect()))

In the code:
idfvector = numpy.array(numpy.transpose(idfvector))
both np.transpose() and np.array() return a NumPy array, so wrapping the result of np.transpose() in np.array() is redundant and causes unnecessary memory copying.
Moreover, it's more efficient and idiomatic to use the .T shorthand for transposition:
idfvector = idfvector.T
This avoids redundant operations, improves readability, and performs better, especially in performance-sensitive code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions