Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8133947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:49:36+00:00 2026-06-06T09:49:36+00:00

I am trying to show correlation between two individual lists. Before installing Numpy, I

  • 0

I am trying to show correlation between two individual lists. Before installing Numpy, I parsed World Bank data for GDP values and the number of internet users and stored them in two separate lists. Here is the snippet of code. This is just for gdp07. I actually have more lists for more years and other data such as unemployment.

import numpy as np

file = open('final_gdpnum.txt', 'r')
gdp07 = []
for line in file:
    fields = line.strip().split()
    gdp07.append(fields [0])    

file2 = open('internetnum.txt', 'r')
netnum07 = []
for line in file2:
    fields2 = line.strip().split()
    nnetnum07.append(fields2 [0])

print np.correlate(gdp07,netnum07,"full")

The error I get is this:

Traceback (most recent call last):
  File "Project3,py", line 83, in ,module.
    print np.correlate(gdp07, netnum07, "full")
  File "/usr/lib/python2.6/site-packages/numpy/core/numeric.py", line 645, in correlate
    return multiarray.correlate2(a,v,mode))
ValueError: data type must provide an itemsize

Just for the record, I am using Cygwin with Python 2.6 on a Windows computer. I am only using Numpy along with its dependencies and other parts of its build (gcc compiler). Any help would be great. Thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:49:37+00:00Added an answer on June 6, 2026 at 9:49 am

    Perhaps that is the error when you try to input data as string, since according to python docs strip() return a string

    http://docs.python.org/library/stdtypes.html

    Try parsing the data to whatever type you want

    As you can see here

    In [14]:np.correlate(["3", "2","1"], [0, 1, 0.5])
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    /home/dog/<ipython-input-14-a0b588b9af44> in <module>()
    ----> 1 np.correlate(["3", "2","1"], [0, 1, 0.5])
    
    /usr/lib64/python2.7/site-packages/numpy/core/numeric.pyc in correlate(a, v, mode, old_behavior)
        643         return multiarray.correlate(a,v,mode)
        644     else:
    --> 645         return multiarray.correlate2(a,v,mode)
        646 
        647 def convolve(a,v,mode='full'):
    
    ValueError: data type must provide an itemsize
    

    try parsing the values

    In [15]: np.correlate([int("3"), int("2"),int("1")], [0, 1, 0.5])
    Out[15]: array([ 2.5])
    
    
    
    import numpy as np
    
    file = open('final_gdpnum.txt', 'r')
    gdp07 = []
    for line in file:
        fields = line.strip().split()
        gdp07.append(int(fields [0]))    
    
    file2 = open('internetnum.txt', 'r')
    netnum07 = []
    for line in file2:
        fields2 = line.strip().split()
        nnetnum07.append(int(fields2 [0]))
    
    print np.correlate(gdp07,netnum07,"full")
    

    your other error is a character ending problem
    i hope this works, since I dont think I can reproduce it since I have a linux box that supports utf-8 by default.
    I went by ipython help(codecs) documentation
    http://code.google.com/edu/languages/google-python-class/dict-files.html

    import codecs
    
    f =  codecs.open(file, "r", codecs.BOM_UTF8)
    for line in f:
        fields = line.strip().split()
        gdp07.append(int(fields [0]))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a matrix of doubles, representing a correlation between entities.
iam trying to show image preview before upload, for that i am using code
We're trying to show 4 trend graphs and will be adding data to them
Trying to show/hide table rows using jquery. First two rows work. The third row
I'm trying to show a UIAlertView before actually deleting a cell from a UITableView
Trying to show a label only when a certain item in a combo is
I am trying to show by example that the prefix increment is more efficient
I'm trying to show updated results for a CCK Computed Field. The computation is
I'm trying to show thumbnail images in Django admin, but I can only see
I'm trying to show the number of times an operation occurred since the last

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.