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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:10:25+00:00 2026-06-04T21:10:25+00:00

I am using the loadtxt function of numpy in python in order to load

  • 0

I am using the loadtxt function of numpy in python in order to load data from a text file to an array. Standard stuff that shouldn’t cause any problem.

I had written a script to do this under ubuntu 10.04 and it worked flawlessly. However I recently upgraded to ubuntu 12.04 (complete reinstall, not an upgrade) and now the script doesn’t work.

Here’s one line from the file, all lines have the same structure: 11 columns separated by tabs:

Av = 0° Bv = 78°    273013  247744  1327      ****  Av' = 156°  Bv = 78°    259197  247803  1551

I want the data of the 5th and 11th column, so I use this command to load the data:
loadtxt(file, usecols=(4,10),delimiter=’\t’)

But it doesn’t work, here what ipython spits out:

In [46]: test=loadtxt(file,usecols=(4,10),delimiter='\t')
--------------------------------------------------------------------------- ValueError   
Traceback (most recent call last)  <ipython-input-46-20a0923eaf9b> in <module>()
----> 1 test=loadtxt(file,usecols=(4,10),delimiter='\t')

/usr/lib/python2.7/dist-packages/numpy/lib/npyio.pyc in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin)
    794                 vals = [vals[i] for i in usecols]
    795             # Convert each value according to its column and store

--> 796             items = [conv(val) for (conv, val) in zip(converters, vals)]
    797             # Then pack it according to the dtype's nesting

    798             items = pack_items(items, packing)

ValueError: could not convert string to float:

It used to work with my old system (ubuntu 10.04) but I can’t manage to load data from this file under my new install (ubuntu 12.04).

If anyone could point me what’s wrong it’d be greatly appreciated!

  • 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-04T21:10:27+00:00Added an answer on June 4, 2026 at 9:10 pm

    I am not sure why loadtxt used to work, it currently doesn’t handle strings very well. But you can use genfromtxt to process this record:

    import numpy as np
    
    out = np.genfromtxt(file, usecols=(4,10), delimiter='\t')
    

    If you omit the usecols and load the entire record, then it replaces the string entries with nans.

    • 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 in data from a text file using numpy.loadtxt with
When I load an array using numpy.loadtxt, it seems to take too much memory.
From a text file containing three columns of data I want to be able
Using Java,I have to fetch multiple sets of values from an XML file to
Using Yii, I want to delete all the rows that are not from today.
I'm trying to read in an Ascii file using loadtxt. The file looks like
I am having some difficulty with importing data from a .csv file. I am
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
A coworker left some data files I want to analyze with Numpy. Each file
Using Android 2.1+. I have a service that gets killed from time to time

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.