Data type added as string when creating variable …array([0., 0., 0., …, 0., 0., 0.], dtype=float32)












0















When I change my array data type, using .astype() or by adding to np.array(list,dtype=), I get an array which has a string attached. Why is this happening? (example below)



In [1]: A=[1,2,3]

In [2]: A=np.array(A,np.float32)

In [3]: A.dtype
Out[3]: dtype('float32')

In [4]: A
Out[4]: array([1., 2., 3.], dtype=float32)

In [5]: AA=[3,4,5]

In [6]: AA=np.array(AA)

In [7]: AA
Out[7]: array([3, 4, 5])

In [8]: AA.dtype
Out[8]: dtype('int32')

In [9]: AA.astype(np.float32())
Out[9]: array([3., 4., 5.], dtype=float32)









share|improve this question





























    0















    When I change my array data type, using .astype() or by adding to np.array(list,dtype=), I get an array which has a string attached. Why is this happening? (example below)



    In [1]: A=[1,2,3]

    In [2]: A=np.array(A,np.float32)

    In [3]: A.dtype
    Out[3]: dtype('float32')

    In [4]: A
    Out[4]: array([1., 2., 3.], dtype=float32)

    In [5]: AA=[3,4,5]

    In [6]: AA=np.array(AA)

    In [7]: AA
    Out[7]: array([3, 4, 5])

    In [8]: AA.dtype
    Out[8]: dtype('int32')

    In [9]: AA.astype(np.float32())
    Out[9]: array([3., 4., 5.], dtype=float32)









    share|improve this question



























      0












      0








      0








      When I change my array data type, using .astype() or by adding to np.array(list,dtype=), I get an array which has a string attached. Why is this happening? (example below)



      In [1]: A=[1,2,3]

      In [2]: A=np.array(A,np.float32)

      In [3]: A.dtype
      Out[3]: dtype('float32')

      In [4]: A
      Out[4]: array([1., 2., 3.], dtype=float32)

      In [5]: AA=[3,4,5]

      In [6]: AA=np.array(AA)

      In [7]: AA
      Out[7]: array([3, 4, 5])

      In [8]: AA.dtype
      Out[8]: dtype('int32')

      In [9]: AA.astype(np.float32())
      Out[9]: array([3., 4., 5.], dtype=float32)









      share|improve this question
















      When I change my array data type, using .astype() or by adding to np.array(list,dtype=), I get an array which has a string attached. Why is this happening? (example below)



      In [1]: A=[1,2,3]

      In [2]: A=np.array(A,np.float32)

      In [3]: A.dtype
      Out[3]: dtype('float32')

      In [4]: A
      Out[4]: array([1., 2., 3.], dtype=float32)

      In [5]: AA=[3,4,5]

      In [6]: AA=np.array(AA)

      In [7]: AA
      Out[7]: array([3, 4, 5])

      In [8]: AA.dtype
      Out[8]: dtype('int32')

      In [9]: AA.astype(np.float32())
      Out[9]: array([3., 4., 5.], dtype=float32)






      python






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 15:24









      Banghua Zhao

      1,2851719




      1,2851719










      asked Nov 14 '18 at 15:18









      AJC123AJC123

      63




      63
























          2 Answers
          2






          active

          oldest

          votes


















          0














          This is not a string: dtype('float32'). It's just one way of representing the dtype for a 32bits float.



          If you had strings in your array, you would see:



          dtype('S1')


          or:



          dtype('object')





          share|improve this answer































            1














            You're converting your types correctly and the , dtype=float32 attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.



            If you do



            print(AA)


            you will only see your array without any strings following.






            share|improve this answer
























            • Why does this only show up for some arrays then?

              – AJC123
              Nov 14 '18 at 15:39











            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%2f53303430%2fdata-type-added-as-string-when-creating-variable-array0-0-0-0%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            This is not a string: dtype('float32'). It's just one way of representing the dtype for a 32bits float.



            If you had strings in your array, you would see:



            dtype('S1')


            or:



            dtype('object')





            share|improve this answer




























              0














              This is not a string: dtype('float32'). It's just one way of representing the dtype for a 32bits float.



              If you had strings in your array, you would see:



              dtype('S1')


              or:



              dtype('object')





              share|improve this answer


























                0












                0








                0







                This is not a string: dtype('float32'). It's just one way of representing the dtype for a 32bits float.



                If you had strings in your array, you would see:



                dtype('S1')


                or:



                dtype('object')





                share|improve this answer













                This is not a string: dtype('float32'). It's just one way of representing the dtype for a 32bits float.



                If you had strings in your array, you would see:



                dtype('S1')


                or:



                dtype('object')






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 14 '18 at 15:25









                Matthieu BrucherMatthieu Brucher

                15.8k32141




                15.8k32141

























                    1














                    You're converting your types correctly and the , dtype=float32 attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.



                    If you do



                    print(AA)


                    you will only see your array without any strings following.






                    share|improve this answer
























                    • Why does this only show up for some arrays then?

                      – AJC123
                      Nov 14 '18 at 15:39
















                    1














                    You're converting your types correctly and the , dtype=float32 attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.



                    If you do



                    print(AA)


                    you will only see your array without any strings following.






                    share|improve this answer
























                    • Why does this only show up for some arrays then?

                      – AJC123
                      Nov 14 '18 at 15:39














                    1












                    1








                    1







                    You're converting your types correctly and the , dtype=float32 attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.



                    If you do



                    print(AA)


                    you will only see your array without any strings following.






                    share|improve this answer













                    You're converting your types correctly and the , dtype=float32 attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.



                    If you do



                    print(AA)


                    you will only see your array without any strings following.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 14 '18 at 15:24









                    Tadej MagajnaTadej Magajna

                    1,1201332




                    1,1201332













                    • Why does this only show up for some arrays then?

                      – AJC123
                      Nov 14 '18 at 15:39



















                    • Why does this only show up for some arrays then?

                      – AJC123
                      Nov 14 '18 at 15:39

















                    Why does this only show up for some arrays then?

                    – AJC123
                    Nov 14 '18 at 15:39





                    Why does this only show up for some arrays then?

                    – AJC123
                    Nov 14 '18 at 15:39


















                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303430%2fdata-type-added-as-string-when-creating-variable-array0-0-0-0%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

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python