相关疑难解决方法(0)

dtypes.Python中S1和S2的区别

我有两个字符串数组:

In [51]: r['Z']
Out[51]: 
array(['0', '0', '0', ..., '0', '0', '0'], 
      dtype='|S1')

In [52]: r['Y']                                                                                                                
Out[52]: 
array(['X0', 'X0', 'X0', ..., 'X0', 'X1', 'X1'], 
      dtype='|S2')
Run Code Online (Sandbox Code Playgroud)

S1和S2有什么区别?只是他们持有不同长度的条目吗?

如果我的数组有不同长度的字符串怎么办?

我在哪里可以找到所有可能的dtypes列表及其含义?

python numpy

14
推荐指数
1
解决办法
1万
查看次数

像在numpy中输入的str的默认dtype是什么?

我只是想确认字符串的默认数据类型是否unicode在创建时ndarray。我找不到任何可以清楚说明这一点的参考。可能是太明显了,不需要说明。

当指定dtype时:

>>> import numpy as np
>>> g = np.array([['a', 'b'],['c', 'd']], dtype='S')
>>> g
array([[b'a', b'b'],
       [b'c', b'd']], 
      dtype='|S1')
Run Code Online (Sandbox Code Playgroud)

不指定dtype:

>>> g = np.array([['a', 'b'],['c', 'd']])
>>> g
array([['a', 'b'],
       ['c', 'd']], 
      dtype='<U1')
Run Code Online (Sandbox Code Playgroud)

同样,b当指定dtype时,文字表示什么。根据文档,它表明bool这里似乎不是这种情况。

可以请一个人澄清一下吗?

python string numpy numpy-dtype

4
推荐指数
1
解决办法
1929
查看次数

标签 统计

numpy ×2

python ×2

numpy-dtype ×1

string ×1