what is "U21" in dtype? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is "U21" in dtype?

I defined np3 as below: np3=np.array([2,3,4,'list']) and then np3.dtype I get this: dtype('<U21') what's the meaning of U21?

22nd May 2023, 9:20 PM
Z.r M
Z.r M - avatar
2 Answers
+ 2
All items of a numpy array must be of the same type. numpy tries to cast efficiently them to a single data type. Read here, for instance: https://stackoverflow.com/questions/65447594/why-does-np-array1-a-consume-unicode-string-of-21-characters
22nd May 2023, 9:30 PM
Lisa
Lisa - avatar
0
Z.r M It's more efficient if you use the same datatype in numpy. try np3 = np.array(["2","3","4","list"]) then np3.dtype is only <U4
23rd May 2023, 5:26 AM
Bob_Li
Bob_Li - avatar