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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:20:34+00:00 2026-06-11T08:20:34+00:00

I generate data using numpy.genfromtxt like this: ConvertToDate = lambda s:datetime.strptime(s,%d/%m/%Y) data= numpy.genfromtxt(open(PSECSkew.csv, rb),

  • 0

I generate data using numpy.genfromtxt like this:

ConvertToDate = lambda s:datetime.strptime(s,"%d/%m/%Y")
data= numpy.genfromtxt(open("PSECSkew.csv", "rb"), 
                        delimiter=',',
                        dtype=[('CalibrationDate', datetime),('Expiry', datetime), ('B0', float), ('B1', float), ('B2', float), ('ATMAdjustment', float)],
                        converters={0: ConvertToDate, 1: ConvertToDate})

I now want to extract the last 4 columns (of each row but in a loop so lets just consider a single row) to separate variables. So I do this:

    B0 = data[0][2]
    B1 = data[0][3]
    B2 = data[0][4]
    ATM = data[0][5]

But if I can do this (like I could with a normal 2D ndarray for example) I would prefer it:

    B0, B1, B2, ATM = data[0][2:]

But this gives me an ‘invalid index’ error. Is there a way to do this nicely or should I stick with the 4 line approach?

  • 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-11T08:20:36+00:00Added an answer on June 11, 2026 at 8:20 am

    As output of np.genfromtxt, you have a structured array, that is, a 1D array where each row as different fields.

    If you want to access some fields, just access them by names:

    data["B0"], data["B1"], ...
    

    You can also group them:

    data[["B0", "B1]]
    

    which gives you a ‘new’ structured array with only the fields you wanted (quotes around ‘new’ because the data is not copied, it’s still the same as your initial array).

    Should you want some specific ‘rows’, just do:

    data[["B0","B1"]][0]
    

    which outputs the first row. Slicing and fancy indexing work too.

    So, for your example:

    B0, B1, B2, ATM = data[["B0","B1","B2","ATMAdjustment"]][0]
    

    If you want to access only those fields row after row, I would suggest to store the whole array of the fields you want first, then iterate:

    filtered_data = data[["B0","B1","B2","ATMAdjustment"]]
    for row in filtered_data:
        (B0, B1, B2, ATM) = row
        do_something
    

    or even :

    for (B0, B1, B2, ATM) in filtered_data:
        do_something
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I generate this HTML using Jade <a class=btn btn-primary btn-large data-toggle=modal href=#websiteModal>
I've recently been trying to generate data contracts from xsd files, using svcutil like
I am trying to generate an HTML page using data gathered in a form
How do I generate page numbers for a multi page data set using javascript?
I am using CherryPy to generate and parse data for a php webpage, but
I'm hoping to generate my server-side and client-side validation (ish) using meta data on
I am using the excellent jTemplates plugin to generate content. Given a data object
I want to generate strong types based on weakly typed data sources, using the
Hi I am able to generate pdf containing table with data using iText. How
I'd like to know a good way to generate several megabytes of random data

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.