[Numpy-discussion] Correlation code from "NumPy 1.5 Beginner's Guide"

Paul Hobson pmhobson at gmail.com
Mon May 14 16:41:45 EDT 2012


On Sun, May 13, 2012 at 9:48 AM, Dinesh Prasad <dprasad830 at yahoo.com> wrote:
> Hello. I am new to the list thanks for accepting my question.
>
> I am trying to run the attached code, directly from the book in the title.
>
> It simply calculates correlation of returns of the stock listed in the
> spreadsheets. could it be that the numPY library is not being recognized on
> my system for some reason?
>
> I installed the 32 bit version of python/numpy. This is to preserve
> compatibility with another application that will trigger the code. I am on
> Windows 7 64 bit Home Edition, however.
>
> Thanks for any suggestions.
>
> -Dinesh

Dinesh,

What errors are you getting? I didn't run your code, but from the
looks of things, you might want to set unpack=False as you read the
data.

In other words, instead of this:
>>> bhp = numpy.loadtxt('BHP.csv', delimiter=',', usecols=(6,), unpack=True)

use this:
>>> bhp = numpy.loadtxt('BHP.csv', delimiter=',', usecols=(6,), unpack=False)

The "unpack" keyword argument makes the np.loadtxt function try to
dump each column into its own variable. It may support dumping the
data to a single tuple, but I don't remember that being the case.
-paul



More information about the NumPy-Discussion mailing list