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

  • Home
  • SEARCH
  • 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 996329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:51:39+00:00 2026-05-16T06:51:39+00:00

I usually don’t post questions on these forums, but I’ve searched all over the

  • 0

I usually don’t post questions on these forums, but I’ve searched all over the place and I haven’t found anything about this issue.

I am working with structured arrays to store experimental data. I’m using titles to store information about my fields, in this case the units of measure. When I call numpy.lib.io.flatten_dtype() on my dtype, I get:

ValueError: too many values to unpack  
File "c:\Python25\Lib\site-packages\numpy\lib\_iotools.py", line 78, in flatten_dtype
  (typ, _) = ndtype.fields[field]

I wouldn’t really care, except that numpy.genfromtxt() calls numpy.lib.io.flatten_dtype(), and I need to be able to import my data from text files.

I’m wondering if I’ve done something wrong. Is flatten_dtype() not meant to support titles? Is there a work-around for genfromtxt()?

Here’s a snippet of my code:

import numpy
fname = "C:\\Somefile.txt"
dtype = numpy.dtype([(("Amps","Current"),"f8"),(("Volts","Voltage"),"f8")])
myarray = numpy.genfromtxt(fname,dtype)
  • 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-16T06:51:40+00:00Added an answer on May 16, 2026 at 6:51 am

    Here is a possible workaround:

    Since your custom dtype causes a problem, supply a flattened dtype instead:

    In [77]: arr=np.genfromtxt('a',dtype='f8,f8')
    
    In [78]: arr
    Out[78]: 
    array([(1.0, 2.0), (3.0, 4.0)], 
          dtype=[('f0', '<f8'), ('f1', '<f8')])
    

    Then use astype to convert to your desired dtype:

    In [79]: arr=np.genfromtxt('a',dtype='f8,f8').astype(dtype)
    
    In [80]: arr
    Out[80]: 
    array([(1.0, 2.0), (3.0, 4.0)], 
          dtype=[(('Amps', 'Current'), '<f8'), (('Volts', 'Voltage'), '<f8')])
    

    Edit: Another alternative is to monkey-patch numpy.lib.io.flatten_dtype:

    import numpy
    import numpy.lib.io
    def flatten_dtype(ndtype):
        """
        Unpack a structured data-type.
    
        """
        names = ndtype.names
        if names is None:
            return [ndtype]
        else:
            types = []
            for field in names:
                typ_fields = ndtype.fields[field]
                flat_dt = flatten_dtype(typ_fields[0])
                types.extend(flat_dt)
            return types
    numpy.lib.io.flatten_dtype=flatten_dtype
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

They usually involve generics. But some methods with generics don't have them, and not
I usually don't use Smarty but am in the process of editing a prebuilt
I usually don't expect help from outside but I need to solve this quickly
net webdeveloper and usually don't make any win32 apps. but now i have to.
I usually don't use onclick, but was gonna do some debug coding for an
I don't know if I can ask this question here. I usually mistake, but...
as I usually don't do the up front design of my models in Django
One of the reasons I usually don't use an IDE for development is that
I don't usually use regular expressions, hence my question. I need a regex to
Drupal has a very well-architected, jQuery -based autocomplete.js . Usually, you don't have to

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.