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

Gael Varoquaux gael.varoquaux at normalesup.org
Fri Oct 10 08:02:35 EDT 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, 
						    nb_windows))
    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.

Cheers,

Gaël



More information about the NumPy-Discussion mailing list