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 6042455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:47:32+00:00 2026-05-23T06:47:32+00:00

I am trying to read in data from a text file using numpy.loadtxt with

  • 0

I am trying to read in data from a text file using numpy.loadtxt with the converters argument. I have a mixture of columns of ints and strings. The code is:

a, b, c, d, e = np.loadtxt(infile, delimiter = ',', usecols=(0, 2, 5, 8, 9), skiprows = 1,
                           unpack = True, converters = dict(zip((0, 2, 5, 8, 9), (int, float, float, int, int))))

The data are read in correctly and unpacked correctly, but all the variables (a, b, c, d, and e) end up as floats. Am I making a mistake in the converters syntax?

Edit trying answer

I tried using dtype = (int,float,float,int,int) as suggested by @joris as:

a,b,c,d,e = np.loadtxt(infile,delimiter = ',', usecols=(0,2,5,8,9), skiprows = 1, unpack = True, dtype = (int,float,float,int,int))

But I get the following error:

     41                                            skiprows = 1,
     42                                            unpack = True,
---> 43                                            dtype = (int,float,float,int,int))
     44
     45

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/npyio.pyc in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack)
    665     try:
    666         # Make sure we're dealing with a proper dtype

--> 667         dtype = np.dtype(dtype)
    668         defconv = _getconv(dtype)
    669

TypeError: data type not understood
WARNING: Failure executing file: <forward_NDMMF.py>

I am using NumPy v. 1.5.1.

  • 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-05-23T06:47:32+00:00Added an answer on May 23, 2026 at 6:47 am

    For specifying the type of the different columns, you can use the argument dtype instead of converters:

    dtype=(int,float,float,int,int)
    

    EDIT:

    Apparantly, this type of dtype specification does not seem to work with loadtxt, but it works with genfromtxt (Does anybody know why this does not work work with loadtxt, or is this one of the extra capabilities of genfromtxt?)

    If you want to use loadtxt, a structured dtype specification with tuples works, like [('f0', int), ('f1', float)] instead of (int, float)

    But there is another problem. When working with such structured dtypes, and so structured arrays (different types for different columns), the unpack does not seem to work. At least with a simple example I tried. But that could be a bug that is already solved: http://projects.scipy.org/numpy/ticket/1458 (but for that, you have to upgrade to even 1.6).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a number from an excelsheet using PHPExcel. The code
Hey! I am trying to put some data from a textbox to an existing
I am receiving a stream of data from a webservice and trying to save
I am trying to add a text file to my project. Not that it
I'm using a Java program to POST some XML data from a remote client
I am trying to extract all the images from a pdf using itextsharp but
Here is link if you want to download application: Simple banking app Text file
I'm writing an ORM using Elixir and SQLAlchemy to handle moving spreadsheet-like data into
I need to parse an XLIFF file using C#, but I'm having some trouble.
I'm trying to write a very simple email script in python. It's basically a

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.