Weird behaviour initializing a numpy array of string data

前端 未结 5 1609
挽巷
挽巷 2020-12-05 22:38

I am having some seemingly trivial trouble with numpy when the array contains string data. I have the following code:

my_array = numpy.empty([1, 2], dty         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 23:22

    I got a "codec error" when I tried to use a non-ascii character with dtype="S10"

    You also get an array with binary strings, which confused me.

    I think it is better to use:

    my_array = numpy.empty([1, 2], dtype="

    Here 'U10' translates to "Unicode string of length 10; little endian format"

提交回复
热议问题