471,353 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,353 software developers and data experts.

Long list to numeric multi-D array

I have a long list of floats (1613808 elements long). It takes quite a
while to load this into a 7 dimensional Numeric array.

Is there any obvious way to speed this up?

def insertData(self,data):

# Start off with an array of the desired size
# "self.MEASURED", etc., are integers
arrayData = zeros([self.MEASURED, self.SWEPT, \
self.TEMPS,self.DCS, self.IVS, self.UUTS, \
self.DUTS], Float64)

i = 0

for device in range(self.DUTS):
for unit in range(self.UUTS):
for iv in range(self.IVS):
for dc in range(self.DCS):
for temp in range(self.TEMPS):
for swept in range(self.SWEPT):
for measured in range(self.MEASURED):

arrayData[measured][swept][temp][dc][iv][unit][device] = bigList[i]
i += 1
return arrayData

Stephen
Jul 18 '05 #1
3 1698
Stephen Boulet wrote:
I have a long list of floats (1613808 elements long). It takes quite a
while to load this into a 7 dimensional Numeric array.

Is there any obvious way to speed this up?

Perhaps reshape will be able to solve this problem for you. I hear it
is very fast.

- Josiah
Jul 18 '05 #2

"Stephen Boulet" <stephendotboulet@motorola_._com> wrote in message
news:bv**********@newshost.mot.com...
I have a long list of floats (1613808 elements long). It takes quite a
while to load this into a 7 dimensional Numeric array.

Is there any obvious way to speed this up?

def insertData(self,data):

# Start off with an array of the desired size
# "self.MEASURED", etc., are integers
arrayData = zeros([self.MEASURED, self.SWEPT, \
self.TEMPS,self.DCS, self.IVS, self.UUTS, \
self.DUTS], Float64)

i = 0

for device in range(self.DUTS):
for unit in range(self.UUTS):
for iv in range(self.IVS):
for dc in range(self.DCS):
for temp in range(self.TEMPS):
for swept in range(self.SWEPT):
for measured in range(self.MEASURED):

arrayData[measured][swept][temp][dc][iv][unit][device] = bigList[i]
i += 1
return arrayData

Stephen


Creating a 1-dimensional array, then reshaping it is (I guess) as quick as
anything. Something like,
import Numeric
an_array = Numeric.array(range(24))
shape = [2, 3, 4]
an_array = Numeric.reshape(an_array, shape)
an_array array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])


Jul 18 '05 #3
To respond to my own post, after a bit of digging, there is a much
faster way.

Coerce my list to a numarray:

bigList = inputarray(bigList,Float64)

Then just change its shape:

dims = [self.DUTS,self.UUTS,..,self.MEASURED]
dims.reverse()
dims = tuple(dims)
bigList.setshape(dims)
Stephen Boulet wrote:
I have a long list of floats (1613808 elements long). It takes quite a
while to load this into a 7 dimensional Numeric array.

Is there any obvious way to speed this up?

def insertData(self,data):

# Start off with an array of the desired size
# "self.MEASURED", etc., are integers
arrayData = zeros([self.MEASURED, self.SWEPT, \
self.TEMPS,self.DCS, self.IVS, self.UUTS, \
self.DUTS], Float64)

i = 0

for device in range(self.DUTS):
for unit in range(self.UUTS):
for iv in range(self.IVS):
for dc in range(self.DCS):
for temp in range(self.TEMPS):
for swept in range(self.SWEPT):
for measured in range(self.MEASURED):

arrayData[measured][swept][temp][dc][iv][unit][device] = bigList[i]
i += 1
return arrayData

Stephen

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Hilde Roth | last post: by
5 posts views Thread by Gary Ruben | last post: by
1 post views Thread by Sergey Olefir | last post: by
1 post views Thread by Joe | last post: by
32 posts views Thread by John Wright | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.