Reading h5 file












0














I am a new python user and I want to read the data from a h5 file. The code that I have used to read the data is given below:



>>> import numpy as np
>>> import h5py
>>> f = h5py.File('file.h5', 'r')
>>> list(f.keys())
[u'data']
>>> dset = f[u'data']
>>> dset.shape
(64, 64, 64)
>>> dset.dtype
dtype(('<f8', (3,)))


Can anyone help me to understand these commands? My questions are:
1. What can I understand by the terms [u'data'] and dtype(('










share|improve this question
























  • Don't know why I can't view the full post...the missing points are given below: Can anyone help me to understand these commands? My questions are: 1. What can I understand by the terms [u'data'] and dtype(('<f8', (3,)))? 2. If I want to view the full data shape (e.g, 64,64,64) then what command I need to use in python script? 3. What is the difference between the commands, 'dset[0:63]' ,'dset[0,63]' and 'dset[0:63, 0:63]'?
    – Photon
    Nov 21 '18 at 1:57












  • If you are new to Python it's hard to know where there are gaps in your knowledge. To me the h5py docs are clear enough. docs.h5py.org/en/latest/high/dataset.html#reading-writing-data. I'd suggest also looking at some of the other h5py tagged questions. Beyond that you need to some basic knowledge of numpy along with python.
    – hpaulj
    Nov 21 '18 at 3:08


















0














I am a new python user and I want to read the data from a h5 file. The code that I have used to read the data is given below:



>>> import numpy as np
>>> import h5py
>>> f = h5py.File('file.h5', 'r')
>>> list(f.keys())
[u'data']
>>> dset = f[u'data']
>>> dset.shape
(64, 64, 64)
>>> dset.dtype
dtype(('<f8', (3,)))


Can anyone help me to understand these commands? My questions are:
1. What can I understand by the terms [u'data'] and dtype(('










share|improve this question
























  • Don't know why I can't view the full post...the missing points are given below: Can anyone help me to understand these commands? My questions are: 1. What can I understand by the terms [u'data'] and dtype(('<f8', (3,)))? 2. If I want to view the full data shape (e.g, 64,64,64) then what command I need to use in python script? 3. What is the difference between the commands, 'dset[0:63]' ,'dset[0,63]' and 'dset[0:63, 0:63]'?
    – Photon
    Nov 21 '18 at 1:57












  • If you are new to Python it's hard to know where there are gaps in your knowledge. To me the h5py docs are clear enough. docs.h5py.org/en/latest/high/dataset.html#reading-writing-data. I'd suggest also looking at some of the other h5py tagged questions. Beyond that you need to some basic knowledge of numpy along with python.
    – hpaulj
    Nov 21 '18 at 3:08
















0












0








0







I am a new python user and I want to read the data from a h5 file. The code that I have used to read the data is given below:



>>> import numpy as np
>>> import h5py
>>> f = h5py.File('file.h5', 'r')
>>> list(f.keys())
[u'data']
>>> dset = f[u'data']
>>> dset.shape
(64, 64, 64)
>>> dset.dtype
dtype(('<f8', (3,)))


Can anyone help me to understand these commands? My questions are:
1. What can I understand by the terms [u'data'] and dtype(('










share|improve this question















I am a new python user and I want to read the data from a h5 file. The code that I have used to read the data is given below:



>>> import numpy as np
>>> import h5py
>>> f = h5py.File('file.h5', 'r')
>>> list(f.keys())
[u'data']
>>> dset = f[u'data']
>>> dset.shape
(64, 64, 64)
>>> dset.dtype
dtype(('<f8', (3,)))


Can anyone help me to understand these commands? My questions are:
1. What can I understand by the terms [u'data'] and dtype(('







python-3.x numpy h5py






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 3:10









hpaulj

110k774140




110k774140










asked Nov 21 '18 at 1:52









Photon

31




31












  • Don't know why I can't view the full post...the missing points are given below: Can anyone help me to understand these commands? My questions are: 1. What can I understand by the terms [u'data'] and dtype(('<f8', (3,)))? 2. If I want to view the full data shape (e.g, 64,64,64) then what command I need to use in python script? 3. What is the difference between the commands, 'dset[0:63]' ,'dset[0,63]' and 'dset[0:63, 0:63]'?
    – Photon
    Nov 21 '18 at 1:57












  • If you are new to Python it's hard to know where there are gaps in your knowledge. To me the h5py docs are clear enough. docs.h5py.org/en/latest/high/dataset.html#reading-writing-data. I'd suggest also looking at some of the other h5py tagged questions. Beyond that you need to some basic knowledge of numpy along with python.
    – hpaulj
    Nov 21 '18 at 3:08




















  • Don't know why I can't view the full post...the missing points are given below: Can anyone help me to understand these commands? My questions are: 1. What can I understand by the terms [u'data'] and dtype(('<f8', (3,)))? 2. If I want to view the full data shape (e.g, 64,64,64) then what command I need to use in python script? 3. What is the difference between the commands, 'dset[0:63]' ,'dset[0,63]' and 'dset[0:63, 0:63]'?
    – Photon
    Nov 21 '18 at 1:57












  • If you are new to Python it's hard to know where there are gaps in your knowledge. To me the h5py docs are clear enough. docs.h5py.org/en/latest/high/dataset.html#reading-writing-data. I'd suggest also looking at some of the other h5py tagged questions. Beyond that you need to some basic knowledge of numpy along with python.
    – hpaulj
    Nov 21 '18 at 3:08


















Don't know why I can't view the full post...the missing points are given below: Can anyone help me to understand these commands? My questions are: 1. What can I understand by the terms [u'data'] and dtype(('<f8', (3,)))? 2. If I want to view the full data shape (e.g, 64,64,64) then what command I need to use in python script? 3. What is the difference between the commands, 'dset[0:63]' ,'dset[0,63]' and 'dset[0:63, 0:63]'?
– Photon
Nov 21 '18 at 1:57






Don't know why I can't view the full post...the missing points are given below: Can anyone help me to understand these commands? My questions are: 1. What can I understand by the terms [u'data'] and dtype(('<f8', (3,)))? 2. If I want to view the full data shape (e.g, 64,64,64) then what command I need to use in python script? 3. What is the difference between the commands, 'dset[0:63]' ,'dset[0,63]' and 'dset[0:63, 0:63]'?
– Photon
Nov 21 '18 at 1:57














If you are new to Python it's hard to know where there are gaps in your knowledge. To me the h5py docs are clear enough. docs.h5py.org/en/latest/high/dataset.html#reading-writing-data. I'd suggest also looking at some of the other h5py tagged questions. Beyond that you need to some basic knowledge of numpy along with python.
– hpaulj
Nov 21 '18 at 3:08






If you are new to Python it's hard to know where there are gaps in your knowledge. To me the h5py docs are clear enough. docs.h5py.org/en/latest/high/dataset.html#reading-writing-data. I'd suggest also looking at some of the other h5py tagged questions. Beyond that you need to some basic knowledge of numpy along with python.
– hpaulj
Nov 21 '18 at 3:08














1 Answer
1






active

oldest

votes


















0














As @hpaulj mentions, the h5py doc is a good reference. You also need to understand basic HDF5 file concepts. It's a big topic. To get started, review the Learning HDF5 pages from The HDF Group. I know (from personal experience) that you will struggle if you don't understand how to navigate the hierarchy. Learn the differences between Group and Dataset objects.



Here's an explanation of the output in your OP.
Note that these are all h5py functions (not numpy).



>>> list(f.keys())
[u'data']


The “keys” are the names of group members, and the “values” are the members (Group and Dataset objects). This is a list of the Node names at the root level of the file. Nodes can be Groups or Datasets. In your case, you have one dataset named data. (The only group in this HDF5 file is the root group: '/', there are no groups below the root.)



The next step accesses the data in the data dataset.



>>> dset = f[u'data']


The shape attribute gives you the dimensions of the dataset:



>>> dset.shape
(64, 64, 64)


The dtype attribute gives you the data types of the dataset (just like numpy):



>>> dset.dtype
type(('<f8', (3,)))


So, you have an array of floats. If you want to see the data, you can enter this (I would only do this for small datasets, or slice to print a few rows):



>>> for row in dset:
print (row)


From here, what you do with the data is up to you.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404251%2freading-h5-file%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As @hpaulj mentions, the h5py doc is a good reference. You also need to understand basic HDF5 file concepts. It's a big topic. To get started, review the Learning HDF5 pages from The HDF Group. I know (from personal experience) that you will struggle if you don't understand how to navigate the hierarchy. Learn the differences between Group and Dataset objects.



    Here's an explanation of the output in your OP.
    Note that these are all h5py functions (not numpy).



    >>> list(f.keys())
    [u'data']


    The “keys” are the names of group members, and the “values” are the members (Group and Dataset objects). This is a list of the Node names at the root level of the file. Nodes can be Groups or Datasets. In your case, you have one dataset named data. (The only group in this HDF5 file is the root group: '/', there are no groups below the root.)



    The next step accesses the data in the data dataset.



    >>> dset = f[u'data']


    The shape attribute gives you the dimensions of the dataset:



    >>> dset.shape
    (64, 64, 64)


    The dtype attribute gives you the data types of the dataset (just like numpy):



    >>> dset.dtype
    type(('<f8', (3,)))


    So, you have an array of floats. If you want to see the data, you can enter this (I would only do this for small datasets, or slice to print a few rows):



    >>> for row in dset:
    print (row)


    From here, what you do with the data is up to you.






    share|improve this answer




























      0














      As @hpaulj mentions, the h5py doc is a good reference. You also need to understand basic HDF5 file concepts. It's a big topic. To get started, review the Learning HDF5 pages from The HDF Group. I know (from personal experience) that you will struggle if you don't understand how to navigate the hierarchy. Learn the differences between Group and Dataset objects.



      Here's an explanation of the output in your OP.
      Note that these are all h5py functions (not numpy).



      >>> list(f.keys())
      [u'data']


      The “keys” are the names of group members, and the “values” are the members (Group and Dataset objects). This is a list of the Node names at the root level of the file. Nodes can be Groups or Datasets. In your case, you have one dataset named data. (The only group in this HDF5 file is the root group: '/', there are no groups below the root.)



      The next step accesses the data in the data dataset.



      >>> dset = f[u'data']


      The shape attribute gives you the dimensions of the dataset:



      >>> dset.shape
      (64, 64, 64)


      The dtype attribute gives you the data types of the dataset (just like numpy):



      >>> dset.dtype
      type(('<f8', (3,)))


      So, you have an array of floats. If you want to see the data, you can enter this (I would only do this for small datasets, or slice to print a few rows):



      >>> for row in dset:
      print (row)


      From here, what you do with the data is up to you.






      share|improve this answer


























        0












        0








        0






        As @hpaulj mentions, the h5py doc is a good reference. You also need to understand basic HDF5 file concepts. It's a big topic. To get started, review the Learning HDF5 pages from The HDF Group. I know (from personal experience) that you will struggle if you don't understand how to navigate the hierarchy. Learn the differences between Group and Dataset objects.



        Here's an explanation of the output in your OP.
        Note that these are all h5py functions (not numpy).



        >>> list(f.keys())
        [u'data']


        The “keys” are the names of group members, and the “values” are the members (Group and Dataset objects). This is a list of the Node names at the root level of the file. Nodes can be Groups or Datasets. In your case, you have one dataset named data. (The only group in this HDF5 file is the root group: '/', there are no groups below the root.)



        The next step accesses the data in the data dataset.



        >>> dset = f[u'data']


        The shape attribute gives you the dimensions of the dataset:



        >>> dset.shape
        (64, 64, 64)


        The dtype attribute gives you the data types of the dataset (just like numpy):



        >>> dset.dtype
        type(('<f8', (3,)))


        So, you have an array of floats. If you want to see the data, you can enter this (I would only do this for small datasets, or slice to print a few rows):



        >>> for row in dset:
        print (row)


        From here, what you do with the data is up to you.






        share|improve this answer














        As @hpaulj mentions, the h5py doc is a good reference. You also need to understand basic HDF5 file concepts. It's a big topic. To get started, review the Learning HDF5 pages from The HDF Group. I know (from personal experience) that you will struggle if you don't understand how to navigate the hierarchy. Learn the differences between Group and Dataset objects.



        Here's an explanation of the output in your OP.
        Note that these are all h5py functions (not numpy).



        >>> list(f.keys())
        [u'data']


        The “keys” are the names of group members, and the “values” are the members (Group and Dataset objects). This is a list of the Node names at the root level of the file. Nodes can be Groups or Datasets. In your case, you have one dataset named data. (The only group in this HDF5 file is the root group: '/', there are no groups below the root.)



        The next step accesses the data in the data dataset.



        >>> dset = f[u'data']


        The shape attribute gives you the dimensions of the dataset:



        >>> dset.shape
        (64, 64, 64)


        The dtype attribute gives you the data types of the dataset (just like numpy):



        >>> dset.dtype
        type(('<f8', (3,)))


        So, you have an array of floats. If you want to see the data, you can enter this (I would only do this for small datasets, or slice to print a few rows):



        >>> for row in dset:
        print (row)


        From here, what you do with the data is up to you.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 19:22

























        answered Nov 21 '18 at 15:08









        kcw78

        308110




        308110






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404251%2freading-h5-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Ottavio Pratesi

            Tricia Helfer

            15 giugno