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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:20:15+00:00 2026-06-14T19:20:15+00:00

HDF datasets from h5py implement a subset of the functionality of numpy arrays, but

  • 0

HDF datasets from h5py implement a subset of the functionality of numpy arrays, but have the advantage that only the data you actually access will be read into memory. I therefore want to work with datasets for as long as I can, and only convert them into arrays when I need some functionality that they lack. To that end, I’ve tried to define a wrapper class which initially contains a dataset and forwards everything to that, but which catches name errors and converts its dataset into an array when this happens. My current implementation is:

class DArr:
    def __init__(self, dset):
        self.arr = dset
    def __getitem__(self, args):
        try:
            return self.arr.__getitem__(args)
        except:
            self.arr = np.array(self.arr)
            return self.arr.__getitem__(args)
    def __getattr__(self, name):
        try:
            return self.arr.__getattr__(name)
        except:
            self.arr = np.array(self.arr)
            return self.arr.__getattr__(name)

However, this fails when self.arr has become a numpy.array, as these apparently do not have a __getattr__ I can forward to. What is the correct way to do this kind of forwarding? The goal is that a DArr should behave just like a numpy.array from the user’s point of view.

  • 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-14T19:20:17+00:00Added an answer on June 14, 2026 at 7:20 pm

    Use the getattr builtin function:

    def __getattr__(self, name):
        try:
            return getattr(self.arr, name)
        except:
            self.arr = np.array(self.arr)
            return getattr(self.arr, name)
    

    For __getitem__ use the [] indexing operator:

    def __getitem__(self, args):
        try:
            return self.arr[args]
        except:
            self.arr = np.array(self.arr)
            return self.arr[args]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large set off files (hdf) that I need to enable search
Does anybody know a simple library to read data from HDF files in .NET
I have three arrays: longitude(400,600),latitude(400,600),data(30,400,60); what I am trying to do is to extract
I have file MOD17A1.A2002047.h20v09.058.2007117021342.hdf that is stored in my database. I have a column
I'm getting ( http://www.hdfgroup.org/projects/hdf.net/ ) The specified module could not be found. (Exception from
I am using xslt 1.0 stylesheet to worlk on xml file data. I have
I have a jar file I produced from compiled class files using an ant
I have an application I'm building that's using the NetCDF C++ library, and NetCDF
I am trying to plot some HDF data in matplotlib. After importing them using
I have 700 files in a single folder. I need to find files that

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.