# [SciPy-user] strange ValueError in scipy_core

Chris Fonnesbeck fonnesbeck at gmail.com
Thu Nov 10 14:29:07 CST 2005

```I am converting some code over to scipy_core which involves populating
a relatively sparse matrix, so I am generating an array of zeros, and
substituting the non-zero elements. However, this substitution does
not seem to be allowed. Here is the relevant section of code.

# Initialize projection matrix
matrix = zeros((10,10),typecode='d')

# Populate with non-zero elements
matrix[0,4] = 0.5*s1
matrix[1,0] = s2
matrix[2,1] = s3
matrix[3,2] = s4*(1.-g4)
matrix[3,3] = sP*(1.-gP)
matrix[4,2] = s4*g4
matrix[4,3] = sP*gP
matrix[4,5] = sA*gB
matrix[5,4] = sA
matrix[5,5] = sA*(1.-gB)
matrix[6,4] = 0.5*s1
matrix[7,6] = s2
matrix[8,7] = s3
matrix[9,8] = s4
matrix[9,9] = sA

But I get the following:

--> 777             matrix[0,4] = 0.5*s1
matrix = [[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,]]
s1 = 0.78583498304255861
778             matrix[1,0] = s2
779             matrix[2,1] = s3

ValueError: cannot handle misaligned or not writeable arrays.

--
Chris Fonnesbeck
Atlanta, GA

```