Home > database >  Strange array output?
Strange array output?

Time:04-09

import numpy as np
x=['a', 'b']
x=np.repeat(x,3)
x[0]="apple"

Why does my code produce ['a' 'a' 'a' 'b' 'b' 'b'] instead of ["apple" 'a' 'a' 'b' 'b' 'b']?

CodePudding user response:

When you use numpy.repeat() your list will contain type numpy.str_ instead of str. numpy.str_  is NumPy datatype used for arrays containing fixed-width byte strings. Check type(x[0]) and type ("apple") to see the difference.

  • Related