np.mean 'str' object has no attribute 'mean' error
Question: I have Python code that worked up until yesterday and now has some floating
problem that I've been unsuccessful at tracking down. I'm trying to calculate
the mean of a list with np.mean but I get an error stating: `AttributeError:
'str' object has no attribute 'mean'`

However if I print out the offending mean calculation:

    
    
    volumetric_power = [x/y for x,y in zip(mcnp_calculated_power,mcnp_vol)]
    print volumetric_power
    normalized_power = [x/np.mean(volumetric_power) for x in volumetric_power]
    

The output I get is an expected list of floats (which I calculated as such):

    
    
    [3.3999658877707657, 3.4055375518790156, 3.3929180596302109, 3.4015594541910334, 3.415077891066217, ... ]
    

Now to try to bypass this I eventually just calculated the average manually
`sum(volumetric_power)/len(volumetric_power)` and I was able to get past the
error. However later in the file I encountered an error with np.loadtxt (the
relevant error here):

    
    
    get_radial_data(filename,zirc_mesh)
    File "./Bicnp.py", line 313, in get_radial_data
    data = np.loadtxt(cwd+'/grope.o', usecols=(1,2,3), skiprows=12)
    AttributeError: 'str' object has no attribute 'loadtxt'
    

After all this I think the error is some Python library type error (using
ignorant lingo) where I'm not sure where to look. All of this worked fine
yesterday, where the one thing I did today was add python27 and python33 from
centos-release-scl per
<http://wiki.centos.org/AdditionalResources/Repositories/SCL>.

Thanks for the help.

Update: I forgot to mention this is running Python 2.6.6


Answer: Somewhere in your code, you are assigning a string object to the `np`
variable. That replaces the numpy module you'd previously imported under that
name, and explains the strange error messages you are seeing (possibly in very
different parts of the code).

If you have a consistent place where you're getting the error, try printing
`np` near there to see what value it has, and then tracking down where you're
making the bad assignment. Just pick a different variable name for the string
and you should be all set.

