[Numpy-discussion] Object too deep for desired array

Karthikesh Raju karthik at james.hut.fi
Thu Jan 30 01:47:03 CST 2003


Hi, 

i was tring out something like this 
import Numeric
import LinearAlgebra
import cmath
import RandomArray
import copy


def sMatrix(pd, code, window):
    if window == 0:
        nprime = 1
    else:
        nprime = window
    
    K, C = Numeric.shape(code)
    K1, L = Numeric.shape(pd)
    # check if K == K1 and raise an exception here
    sCode = Numeric.zeros([nprime*C,K*L*(window+1)],'d')

    for k in range(K):
        for l in range(L):
            code1 = copy.deepcopy(Numeric.array(code[k,0:C-pd[k,l]]))
            code1.shape = (C-pd[k,l],1)
            sCode1=
Numeric.concatenate((Numeric.zeros([pd[k,l],1]),Numeric.zeros([C*window,1]),code1))
            sCode[:, (window+1)*l+window*L*k] = copy.deepcopy(sCode1)
    
    return sCode

if __name__ == "__main__":
    pd = Numeric.array([[2]])
    code = Numeric.array([[-1,1,-1,1,1]])
    np = sMatrix(pd,code,0)
    print np
    print "--"*30
    np = sMatrix(pd,code,1)
    print Numeric.shape(np)
    print np
    print "--"*30
    np = sMatrix(pd,code,2)
    print Numeric.shape(np)
    print np
    print "--"*30


------------------------------
And i get struck with the following error message::

Traceback (most recent call last):
  File "sMatrix.py", line 31, in ?
    np = sMatrix(pd,code,0)
  File "sMatrix.py", line 24, in sMatrix
    sCode[:, (window+1)*l+window*L*k] = copy.deepcopy(sCode1)
ValueError: Object too deep for desired array


------------

i think it is due to the many deep copy operations taht i am performing. i
want to be in a position where slices of matrices should not be
references, but should be copies itself and i should be able to move these
copies around. (May be it is inefficient, but that is what i did in
Matlab and want some compatibility, till i learn more of python and till
i migrate to python completely).

Is there a way out? Why is this an problem? Am i missing something.

Best regards,

karthik








































-----------------------------------------------------------------------
Karthikesh Raju,		    email: karthik at james.hut.fi		
Researcher,			    http://www.cis.hut.fi/karthik
Helsinki University of Technology,  Tel: +358-9-451 5389
Laboratory of Comp. & Info. Sc.,    Fax: +358-9-451 3277
Department of Computer Sc.,
P.O Box 5400, FIN 02015 HUT,
Espoo, FINLAND
-----------------------------------------------------------------------






More information about the Numpy-discussion mailing list