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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:09:39+00:00 2026-06-10T19:09:39+00:00

Thanks guys, that really helped. My main problem as you all pointed out was

  • 0

Thanks guys, that really helped. My main problem as you all pointed out was that I had 4 white spaces rather than a tab!

I have a textfile of the format:

string001    124.342
string002    235.111
string003    552.145

With a blank line at the bottom.

I just want to read this into an array. I thought that the best way to do this would be loadtxt from numpy, but when this didn’t work, I went for genfromtxt, but couldn’t quite get it to work either. This is what I have as my latest effort:

y = np.genfromtxt('1400list.txt',delimiter="\t", dtype=[('mystring','S10'),('myint','i8')])

print y

But I get the error:

rows = np.array(data, dtype=[('', _) for _ in dtype_flat])
ValueError: size of tuple must match number of fields.

Could anyone please help me to figure this one out?

Thank you!

  • 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-10T19:09:40+00:00Added an answer on June 10, 2026 at 7:09 pm

    Your code works fine here (although I suppose you want to use float dtype instead of integer one) with Python 2.7 and numpy 1.5.1:

    #!/usr/bin/env python
    import numpy
    
    y = numpy.genfromtxt('1400list.txt', delimiter='\t',dtype=[('A', 'S10'),
    ('B', 'i8')])
    print y
    

    The output is:

    vicent@deckard:/tmp$ python prova.py 
    [('string001', 124L) ('string002', 235L) ('string003', 552L)]
    vicent@deckard:/tmp$
    

    Please, make sure that you are using tabs instead of spaces in your data file.

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

Sidebar

Related Questions

First of all, thanks so much to everyone who has helped me on this
EDIT: Thanks guys - perfect! I wish I could check more than one answer,
Hey guys thanks for answering I'm really new to Android programming(I started today) and
thanks guys.i managed to complete it.million thanks again specially for DAVID,WM-EDDIE and S.LOTT.also STACKOVERFLOW
Update: Thanks guys, I didn't realize it was very close to zero but not
Hi guys thanks for pay attention to this. Well im trying to replace every
I've come to bother you all with another probably really simple C question. Using
I have a small java program that searches the contents of all *.txt files
I don't really know how to even search for resolution of this problem, didn't
So, simple question really. :) I had this following code with ASPX View Engine

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.