dot() and tensordot()

2008-03-09 Thread royG
hi
can numpy.dot() be used instead of tensordot()? is there any
performance difference? I am talking about operation btw numpy arrays
of dimensions 50 X 20,000 where elements are of float type.

i tried posting in numpy group where i had gotten membership..but when
i post a msg it says posting by non member and so doesn't show up :-(

royG
-- 
http://mail.python.org/mailman/listinfo/python-list


parsing directory for certain filetypes

2008-03-10 Thread royG
hi
i wrote a function to parse a given directory and make a sorted list
of  files with .txt,.doc extensions .it works,but i want to know if it
is too bloated..can this be rewritten in more efficient manner?

here it is...

from string import split
from os.path import isdir,join,normpath
from os import listdir

def parsefolder(dirname):
filenms=[]
folder=dirname
isadr=isdir(folder)
if (isadr):
dirlist=listdir(folder)
filenm=""
for x in dirlist:
 filenm=x
 if(filenm.endswith(("txt","doc"))):
 nmparts=[]
 nmparts=split(filenm,'.' )
 if((nmparts[1]=='txt') or (nmparts[1]=='doc')):
  filenms.append(filenm)
filenms.sort()
filenameslist=[]
filenameslist=[normpath(join(folder,y)) for y in filenms]
numifiles=len(filenameslist)
print filenameslist
return filenameslist


folder='F:/mysys/code/tstfolder'
parsefolder(folder)


thanks,
RG
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parsing directory for certain filetypes

2008-03-10 Thread royG
On Mar 10, 8:03 pm, Tim Chase  wrote:

> In Python2.5 (or 2.4 if you implement the any() function, ripped
> from the docs[1]), this could be rewritten to be a little more
> flexible...something like this (untested):
>

that was quite a good lesson for a beginner like me..
thanks guys

in the version using glob()
>path = os.path.normpath(os.path.join(folder, '*.txt'))
>lst = glob.glob(path)

is it possible to check for more than one file extension? here i will
have to create two path variables like
path1 = os.path.normpath(os.path.join(folder, '*.txt'))
path2 = os.path.normpath(os.path.join(folder, '*.doc'))

and then use glob separately..
or is there another way?

RG
-- 
http://mail.python.org/mailman/listinfo/python-list


rmdir problem

2008-03-11 Thread royG
hi
i am checking if a directory exists and if it does i want to delete it
and its contents.then i want to create the directory before creating
files in it.

def myfolderops():
testdir='..\mytestdir'
#if dir exist remove it
if isdir(testdir):
rmdir(testdir)
#again create directory
mkdir(testdir)

I am working on WinXP and logged in as admin in WinXP. when there is
no dir called '..\mytestdir' or an empty dir  this code works removing
and creating the directory.but if the directory exists with contents
already then it causes an error 145 when rmdir is executed.the message
says 'directory is not empty'
 what should i do  to correct this?
(i need to remove the dir with its contents because each time i will
be putting diff files into it and donot want them to be mixed with old
files)

thanks
RG
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: rmdir problem

2008-03-11 Thread royG
On Mar 11, 3:37 pm, Paul
> Have a look at shutil.rmtree
>
thanks Paul
RG

-- 
http://mail.python.org/mailman/listinfo/python-list


need a function to create eigenface image

2008-03-18 Thread royG
hi
while trying to make an eigenface image from a numpy array of floats i
tried this

from numpy import array
import Image

imagesize=(200,200)
def makeimage(inputarray,imagename):
  inputarray.shape=(-1,)
  newimg=Image.new('L', imagesize)
  newimg.putdata(inputarray)
  newimg.save(imagename)

since i am using images of 200X200 size,
i use an array with 4 elements  like
[ -92.35294118  -81.88235294  -67.58823529 ...,   -3.47058824
   -13.23529412   -9.76470588]
the problem is ,i get an image that is too dark.it looks like a face
but is too dark that even different arrays will create images rhat all
look alike!..
is there a way to 'tone it down' so that i can generate an eigenface
that can be displayed better?

thanks
RG
-- 
http://mail.python.org/mailman/listinfo/python-list


changing names of items in a list

2008-03-19 Thread royG
hi
i am trying to rename extension of files in a directory..as an initial
step i made a method in

class ConvertFiles:
 def __init__(self,infldr,outfldr):
 self.infldr=infldr
 self.outfldr=outfldr
 self.origlist=os.listdir(infldr)

 def renamefiles(self,extn):
 for x in self.origlist:
 x=x+"."+extn

...

later when i print self.origlist  i find that the elements of list are
unchanged..even tho  a print x  inside the renamefiles()  shows that
extn is appended to x  ..
why does this happen?
RG



-- 
http://mail.python.org/mailman/listinfo/python-list


how to remove suffix from filename

2008-03-19 Thread royG

hi
when parsing a list of filenames like ['F:/mydir/one.jpg','F:/mydir/
two.jpg'] etc i want to extract the
basename without the suffix...ie i want to get 'one','two' etc and not
'one.jpg'

is there a function in python to do this or do i have tosplit it ..?
thanks
RG
-- 
http://mail.python.org/mailman/listinfo/python-list


dividing tuple elements with an int or float

2008-03-19 Thread royG
hi
i am trying to resize some images.First i'd read the size as a 2
tuple  and then i want to divide it by 2 or 4 or 2.5 etc..

suppose
origsz=(400,300)
i want to divide the origsize by 2.5 so i can resize to (160,120)

scale=2.5
how can i get the newsz?
obviously origsz/2.5 won't work  ..
thanks
RG
-- 
http://mail.python.org/mailman/listinfo/python-list