Skip to content

Instantly share code, notes, and snippets.

@stober
Created August 15, 2012 20:33
Show Gist options
  • Save stober/3363364 to your computer and use it in GitHub Desktop.
Save stober/3363364 to your computer and use it in GitHub Desktop.
Sparse Matrix Failure
#! /usr/bin/env python
"""
Author: Jeremy M. Stober
Program: ERROR.PY
Date: Thursday, August 2 2012
Description: Example of how sparse matrix operations may fail.
"""
import numpy as np
import scipy.sparse as sp
A = np.ones((3,4))
np.multiply(A, A[0]) # arrays are ok
B = np.asmatrix(A)
np.multiply(B, B[0]) # matrices are ok
C = sp.csc_matrix(A)
np.multiply(C, C[0]) # sparse matrix fails
C.multiply(C[0]) # sparse matrix fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment