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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:40:11+00:00 2026-06-06T12:40:11+00:00

Is is possible to have a 3-D record array in numpy? (Maybe this is

  • 0

Is is possible to have a 3-D record array in numpy? (Maybe this is not possible, or there is simply an easier way to do things too — I am open to other options).

Assume I want an array that holds data for 3 variables (say temp, precip, humidity), and each variable’s data is actually a 2-d array of 2 years (rows) and 6 months of data (columns), I could create that like this:

>>> import numpy as np

>>> d = np.array(np.arange(3*2*6).reshape(3,2,6))
>>> d

#
# comments added for explanation...
#        jan   feb   mar   apr   may   Jun    

array([[[ 0,    1,    2,    3,    4,    5],   # yr1  temp
        [ 6,    7,    8,    9,   10,   11]],  # yr2  temp

       [[12,   13,   14,   15,   16,   17],   # yr1  precip
        [18,   19,   20,   21,   22,   23]],  # yr2  precip

       [[24,   25,   26,   27,   28,   29],   # yr1  humidity
        [30,   31,   32,   33,   34,   35]]]) # yr2  humidity

I’d like to be able to type:

>>> d['temp']

and get this (the first “page” of the data):

>>> array([[ 0,  1,  2,  3,  4,  5],
           [ 6,  7,  8,  9, 10, 11]])

or:

>>> d['Jan']   # assume months are Jan-June

and get this

>>> array([[0,6],
          [12,18],
          [24,30]])

I have been through this: http://www.scipy.org/RecordArrays a number of times, but don’t see how set up what I am after.

  • 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-06T12:40:13+00:00Added an answer on June 6, 2026 at 12:40 pm

    Actually, you can do something similar to this with structured arrays, but it’s generally more trouble than it’s worth.

    What you want is basically labeled axes.

    Pandas (which is built on top of numpy) provides what you want, and is a better choice if you want this type of indexing. There’s also Larry (for labeled array), but it’s largely been superseded by Pandas.

    Also, you should be looking at the numpy documentation for structured arrays for info on this, rather than an FAQ. The numpy documentation has considerably more information. http://docs.scipy.org/doc/numpy/user/basics.rec.html

    If you do want to take a pure-numpy route, note that structured arrays can contain multidimensional arrays. (Note the shape argument when specifying a dtype.) This will rapidly get more complex than it’s worth, though.

    In pandas terminology, what you want is a Panel. You should probably get familiar with DataFrames first, though.

    Here’s how you’d do it with Pandas:

    import numpy as np
    import pandas
    
    d = np.array(np.arange(3*2*6).reshape(3,2,6))
    
    dat = pandas.Panel(d, items=['temp', 'precip', 'humidity'], 
                          major_axis=['yr1', 'yr2'], 
                          minor_axis=['jan', 'feb', 'mar', 'apr', 'may', 'jun'])
    
    print dat['temp']
    print dat.major_xs('yr1')
    print dat.minor_xs('may')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a requirement to have not-so-trivial dynamic list, each record of which consists
I have this SimpleXML object: object(SimpleXMLElement)#176 (1) { [record]=> array(2) { [0]=> object(SimpleXMLElement)#39 (2)
Is it possible, in any way, to pass a Generic Record in an array
Possible Duplicate: Retrieving the last record in each group I have two tables set
Possible Duplicate: Error loading Active Record gem with sinatra app using RVM I have
is it possible to record a video straight to Youtube? Say I have a
Using PostgreSQL triggers, is it possible to record the changes that have happened to
Is it possible to have php not to require the begin/end tags ( <?php
I have an array which holds a record from a CSV file. Can I
I have a record that contains a dynamic array. It is normal that when

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.