[Numpy-discussion] Import NumPy in Self-defined function script

Tim timlee126@yahoo....
Sun Feb 22 17:19:10 CST 2009


Hi,
I am defining a function in file "trainer.py". It requires a module called numpy as following:

[code]
from numpy import *
import string

def trainer(train_seqs):

    nul_dict = {"A":0,"C":1,"G":2,"T":3}# nucleotide to index of array
    init_prob = zeros(4,double)# initial prob at  1st col
    tran_prob = zeros([5,4,4],double)# transition prob indexed by ( col, nul in previous col, nul in current col)
    for line in train_seqs: # counts
        if line != '\n':
            z = line.split()
            z = z[0]
            init_prob[nul_dict[z[0]]] += 1
            for i in range(0,5):
                tran_prob[i][nul_dict[z[i]]][nul_dict[z[i+1]]] += 1
    

    init_prob /= init_prob.sum() # normalize transition initial prob
[/code]

Another script "controller.py" calls this function as:

[code]#! /usr/bin/env python
# from numpy import *
import string
import trainer

import pdb; pdb.set_trace()

ESE_file = file("./ESE.txt",'r')
ESE_seqs = ESE_file.readlines()
ESE_file.close()

ESE_model=trainer.trainer(ESE_seqs)           
[/code]

When I try to tun "controller.py", I get the error:
[quote]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "controller.py", line 12, in <module>
    ESE_model=trainer.trainer(ESE_seqs)
  File "trainer.py", line 4, in trainer
    
NameError: global name 'zeros' is not defined
[/quote]

I think zeros belongs to Module numpy, and I import it in my function file "trainer.py". So I was wonering what's the mistake I am making?  Thanks for help!

-Tim



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090222/89422a28/attachment.html 


More information about the Numpy-discussion mailing list