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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:34:52+00:00 2026-05-26T04:34:52+00:00

I read in a sequence of numbers with np.array(f.read().split(),dtype=np.float64) Then I convert this to

  • 0

I read in a sequence of numbers with

np.array(f.read().split(),dtype=np.float64)

Then I convert this to a 2-D array using np.reshape().

After this, how do to convert arr to a record array? I’ve tried (something like) the following:

filename = 'unstructured-file.txt'
nfields = 3
names = ('r','g','b')
with open(filename,'r') as f:
    arr = np.array(f.read().split(),dtype=np.float64)
    arr = arr.reshape(-1,nfields)
    out = np.array(arr,dtype=zip(names,['float64']*length(names))

but says TypeError: expected a readable buffer object

Any suggestions?

Edit: The main thing I want to do is to name my columns.

Instead of

out = np.array(arr,dtype=zip(names,['float64']*length(names))

If I use this,

out = np.core.records.fromrecords(arr.reshape(-1,nfields),names=','.join(names))

I can use out['r'] and so on, but out.dtype.names is None`. What is going on?

Edit2

The unstructured file looks like

 Some text
 More text
       100  1.000000E-01        46
 -1.891701E+04  1.702921E+02 -2.323660E+04  4.547841E+03 -2.778444E+04
  0.000000E+00  0.000000E+00  0.000000E+00  0.000000E+00 -2.149862E+04
  1.753467E+02  3.410277E+03 -1.034898E+05  2.778692E+04  0.000000E+00
  0.000000E+00  0.000000E+00  0.000000E+00  1.492281E+04  0.000000E+00
  0.000000E+00  0.000000E+00  9.000000E+01  9.000000E+01  9.000000E+01
  0.000000E+00 -4.774939E-01  0.000000E+00  0.000000E+00  0.000000E+00
 -2.243495E-01  3.513048E-01 -2.678782E-01  3.513048E-01 -7.155493E-01
  5.690034E-01 -2.678782E-01  5.690034E-01 -4.783123E-01  2.461974E+01
  0.000000E+00  0.000000E+00  0.000000E+00  2.461974E+01  0.000000E+00
  0.000000E+00  0.000000E+00  2.461974E+01
       200  2.000000E-01        46
 -1.891815E+04  1.421984E+02 -2.424678E+04  5.199451E+03 -2.944623E+04
  0.000000E+00  0.000000E+00  0.000000E+00  0.000000E+00 -2.174561E+04
  1.274613E+02 -6.004790E+01 -1.139308E+05  2.944807E+04  0.000000E+00
  0.000000E+00  0.000000E+00  0.000000E+00  1.445855E+04  0.000000E+00
  0.000000E+00  0.000000E+00  9.000000E+01  9.000000E+01  9.000000E+01
  0.000000E+00  7.785923E-01  0.000000E+00  0.000000E+00  0.000000E+00
  8.123304E-01  3.023486E-01 -5.891595E-01  3.023486E-01 -8.560144E-02
 -3.830618E-01 -5.891595E-01 -3.830618E-01  1.608437E+00  2.436174E+01
  0.000000E+00  0.000000E+00  0.000000E+00  2.436174E+01  0.000000E+00
  0.000000E+00  0.000000E+00  2.436174E+01
  • 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-26T04:34:53+00:00Added an answer on May 26, 2026 at 4:34 am

    To convert a plain numpy array to a structured array, use view:

    import numpy as np
    
    filename = 'unstructured-file.txt'
    nfields = 3
    names = ('r','g','b')
    with open(filename,'r') as f:
        arr = np.array(f.read().split(),dtype=np.float64)
        arr = arr.reshape(-1,nfields)
        out = arr.view(dtype=zip(names,['float64']*len(names))).copy()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Read on before you say this is a duplicate, it's not. (as far as
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read in this article that a company has created a software capable of
I'm not sure what Bjarne meant with this exercise: Convert the desk calculator to
I have Clojure function that takes a sequence of numbers chops it into the
I have to read a txt file with lines formated like this: 1: (G,
I've been playing this flash game and after I'd gotten over the initial ('lol,
Why will this loop not terminate? The program freezes after it prints out all
In part of my java program I read a sequence of inputs for the
i have to read a sequence of bytes,that was written in different ways (writeBite,

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.