[Numpy-discussion] Vectorizing "dot" on the two last axis

Gael Varoquaux gael.varoquaux@normalesup....
Fri Oct 10 07:02:35 CDT 2008

Hi list,

I have been unable to vectorize the following operation::

    window_size = 10
    nb_windows = 819
    nb_clusters = 501
    restricted_series = np.random.random(size=(window_size, nb_clusters, 
    this_cov = np.zeros((nb_windows, nb_clusters, nb_clusters))
    print >>sys.stderr, "alive"
    for index, window in enumerate(restricted_series):
        this_cov[index, ...] = np.dot(window, window.T)

The last for loop is the one I am unhappy with.

Note that it is fairly easy to get huge arrays when trying the vectorize
this through np.dot or np.tensordot.

I am unhappy with myself: I feel that it should be possible to vectorize
this operation, but I cannot figure it out.



More information about the Numpy-discussion mailing list