Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scipy import sparse
- from numpy.linalg import norm
- vector1 = sparse.csr_matrix([ 0 for i in xrange(4000000) ], dtype = float64)
- #just to test I set a few points to a value higher than 0
- vector1[ (0, 10) ] = 5
- vector1[ (0, 1500) ] = 80
- vector1[ (0, 2000000) ] = 6
- n = norm(t1)
- ValueError: dimension mismatch
- norm(asarray(vector1.todense()))
- (vector1.data ** 2).sum()
- # sparseLib.pyx
- #cython: boundscheck=False
- from cython.parallel cimport prange
- from cython.view cimport array as cvarray
- import numpy as np
- from libc.math cimport sqrt
- cpdef double sparseNorm2(double [:] data) nogil:
- cdef long i
- cdef double value = 0.0
- for i in xrange(data.shape[0]):
- value += data[i]*data[i]
- return sqrt(value)
Add Comment
Please, Sign In to add comment