Skip to main content
`Ctrl`+`K`
scipy.sparse.coo_array.

# dot

coo_array.dot(other)

  Return the dot product of two arrays.

  Strictly speaking a dot product involves two vectors. But in the sense that an array with ndim >= 1 is a collection of vectors, the function computes the collection of dot products between each vector in the first array with each vector in the second array. The axis upon which the sum of products is performed is the last axis of the first array and the second to last axis of the second array. If the second array is 1-D, the last axis is used.

  Thus, if both arrays are 1-D, the inner product is returned. If both are 2-D, we have matrix multiplication. If other is 1-D, the sum product is taken along the last axis of each array. If other is N-D for N>=2, the sum product is over the last axis of the first array and the second-to-last axis of the second array.

  Parameters:
    other array_like (dense or sparse)

      Second array

  Returns:
    output array (sparse or dense)

      The dot product of this array with other. It will be dense/sparse if other is dense/sparse.

  Examples

      >>> import numpy as np
      >>> from scipy.sparse import coo_array
      >>> A = coo_array([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
      >>> v = np.array([1, 0, -1])
      >>> A.dot(v)
      array([ 1, -3, -1], dtype=int64)

  For 2-D arrays it is the matrix product:

      >>> A = coo_array([[1, 0], [0, 1]])
      >>> B = coo_array([[4, 1], [2, 2]])
      >>> A.dot(B).toarray()
      array([[4, 1],
             [2, 2]])

  For 3-D arrays the shape extends unused axes by other unused axes.

      >>> A = coo_array(np.arange(3*4*5*6)).reshape((3,4,5,6))
      >>> B = coo_array(np.arange(3*4*5*6)).reshape((5,4,6,3))
      >>> A.dot(B).shape
      (3, 4, 5, 5, 4, 3)