Hello,
I would like to reshape and then transpose data that I import from a file. I downloaded the 'numarray' to access the shape and transpose functions since I am using python version 2.5. This is the pdf I'm using: http://stsdas.stsci.edu/numarray/numarray-1.5.pdf

The data is one long column (length=455), I will attach the data file in the next post to this thread.

However, I am not able to successfully reshape after multiple tries with a couple functions (see the errors embedded in the code).

Is the list not a 1-D array that can be manipulate by shape?
Suggestions are cordially invited.

#Import Modules
import os, copy, numarray

workDIR = "C:\\temp"
os.chdir(workDIR)
data=[]
#for filex in runlist:
x=open('datacol.txt','r')
for i in xrange(455):
    z=x.readline()
    z=float(z)
    data.append(z)
new=numarray.reshape(data(5,91))#this line returns the error below:
new=reshape(data(5,91))#this line also returns the error below:
##Traceback (most recent call last):
##  File "C:/work/scripts/RESAMPLER2dani.py", line 19, in <module>
##    new=reshape(data(5,91))
##    NameError: name 'reshape' is not defined

new=data.shape(5,91)#this line returns the error:
##File "C:/work/scripts/RESAMPLER2dani.py", line 19, in <module>
##    new=data.shape(5,91)
##AttributeError: 'list' object has no attribute 'shape' 
##

new_tr=transpose(data)

Recommended Answers

All 3 Replies

Here is the data set.

numarray.reshape doesn't apply to python lists. It applies to numarray.NumArray, which is a different type with a specific implementation. You can write

data2 = numarray.array(data)
data3 = numarray.reshape(data2, 5, 91)

Okay, I see the Numarray light now, thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.