ijustwantedtoconfirmifthedefaultdatatypeforstringisunicodewhilecreatingandarray.icouldnotfindanyreferencewhichstatesthisclea
When dtype is specified:
import numpy as np
g=NP.Array(['a ',' b'jzdlb,['c ',' d'jzdlbjzdlb,dtype='S
g
Array([b'a ',b'b'jzdlb,
[b'c ',b'd'jzdlbjzdlb,
dtype偏好的吐司/pwithoutspecifyingthedtype :
g=NP.Array(['a ',' b'jzdlb,['c ',' d'jzdlbjzdlb
g
Array(['a ',' b'jzdlb,
['c ',' d'jzdlb,
dtype='
Also,whatdoestheliteralbindicatewhendtypeisspecified.asperthedocumentation,itindicatesboolwhichdoesn ' tseeeemtobetobethecasetethecasesesese
Can some one please clarify?
b ' . ' means it ' sa byte-stringandthedefaultdtypeforarraysofstringsdependsonthekindofstrings.unicodes (python 3字符串阵列) thedt ypes.youcanfindtheexplanationofdtypesinthenumpydocumentationhere
阵列协议类型字符串
thefirstcharacterspecifiesthekindofdataandtheremainingcharactersspecifythenumberofbytesperitem,except for Unicode, wereitisinterpretedasthenumberofcharacters.theitemsizemustcorrespondtoanexistingtype,oranerrorwillberaised.the suported
'? 布尔型
' b ' (已签名)字节
' b '未指定字节
“I”(签名) integer
' u' unsigned integer
' f '浮动点
' c' complex-floating point
' m' timedelta
' M' datetime
“O' (Python )对象
' s ',' a ' zero-terminated bytes (不建议) )。
' u ' unicode字符串
(' v '原始数据(void ) )。
howeverinyourfirstcaseyouactuallyforcednumpytoconvertittobytesbecauseyouspecifieddtype=' s '。