Weird behaviour initializing a numpy array of string data

前端 未结 5 1517
挽巷
挽巷 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:31

    What works best if you are doing a for loop is to start a list comprehension, which will allow you to allocate the right memory.

    data = ['CAT','APPLE,'CARROT']
    my_array = [name for name in data]
    

提交回复
热议问题