omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Converting "*.dat" to array...

    Pythonista
    pythonista read file
    4
    10
    6434
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • iBayern
      iBayern last edited by

      Converting "*.dat" to array...

      I have imported "banana.dat" data file to pythonista... i want to convert it to array using following code...

      from numpy import *
      DataIn = loadtxt('banana.dat')
      

      But, I got error...I don not know what is the problem.

      1 Reply Last reply Reply Quote 0
      • Webmaster4o
        Webmaster4o last edited by

        What's the error?

        1 Reply Last reply Reply Quote 0
        • iBayern
          iBayern last edited by

          Could not convert string to float: @relation

          1 Reply Last reply Reply Quote 0
          • Webmaster4o
            Webmaster4o last edited by

            Copy the full stack, please. Are you on the beta, or on 2.0

            1 Reply Last reply Reply Quote 0
            • iBayern
              iBayern last edited by

              @Webmaster4o said:

              stack

              Thank you for your quick answers.

              The header is:
              @relation banana
              @attribute At1 real[-3.09,2.81]
              @attribute At2 real[-2.39,3.19]
              @attribute Class {-1.0,1.0}
              @inputs At1, At2
              @outputs Class
              @data
              1.14,-0.114,-1.0
              -1.52,-1.15,1.0
              -1.05,0.72,-1.0
              -0.916,0.397,1.0
              -1.09,0.437,1.0
              -0.584,0.0937,1.0
              1.83,0.452,-1.0
              -1.25,-0.286,1.0
              1.7,1.21,1.0
              -0.482,-0.485,1.0
              1.79,-0.459,-1.0

              I'm using the version 2.0...Maybe the problem is the header...how can I remove the deader?

              1 Reply Last reply Reply Quote 0
              • omz
                omz last edited by

                You can ignore the lines starting with @ by passing a comments argument to loadtxt. You also need to specify the delimiter, which is a comma in your case, but whitespace by default. This should work:

                from numpy import *
                data = loadtxt('banana.dat', comments='@', delimiter=',')
                
                iBayern 1 Reply Last reply Reply Quote 1
                • iBayern
                  iBayern @omz last edited by

                  @omz

                  Thank you very much indeed...it works.

                  1 Reply Last reply Reply Quote 1
                  • Webmaster4o
                    Webmaster4o last edited by

                    Of course, my most sarcastic answer would be this

                    Phuket2 1 Reply Last reply Reply Quote 1
                    • Phuket2
                      Phuket2 @Webmaster4o last edited by

                      @Webmaster4o LOL...you have too much time on your hands

                      1 Reply Last reply Reply Quote 1
                      • iBayern
                        iBayern last edited by

                        :) usually I do use your sarcastic way:D This time, I just wanted to find the answer more qickly.

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors