[SciPy-user] vstack / hstack question n dim array without value
Unknown
pitfall66 at freenet.de
Tue Sep 23 08:22:48 EDT 2008
Hello I am programming this for the Machine Learning Course. I am
studying Computer Science.
My Question is can I somehow get rid of the "indices_buffer". Means is
there a easy way to initialize n dim arrays without values ?
I also came up with filling the array with a colum of zeros and deleting
this colum later, but not so elegant in my opinion either.
specifically this code:
indices_buffer=[]
if (indices_buffer==[]):
indices_buffer=tmp
else:
indices_buffer=hstack((indices_buffer,tmp))
--------------------------------------------
data
0.3 0.4 0.4
0.2 0.1 0.3
0.3 0.2 0.4
...
cls
1
1
2
...
def splitcrossval(data,nFold,cls):
indices_buffer=[]
(rows,columns)=data.shape
classes=unique(cls)
for i in classes:
indices=where(cls==i)[0]
tmp=hsplit((permutation(indices)),nFold)
if (indices_buffer==[]):
indices_buffer=tmp
else:
indices_buffer=hstack((indices_buffer,tmp))
return indices_buffer
More information about the SciPy-User
mailing list