首先想到使用np.empty()函数,如下:
matrix1=np.empty(shape=(31,22),dtype=str)
但是发现数组中每个元素仅保留单个字符,无法完整填入字符串。
于是更改使用np.zeros()函数,再将数据类型改为字符型,并将0值替换为空值,就得到了想要的空字符串数组。
matrix1=np.zeros(shape=(31,22)).astype(np.str_)
matrix1[matrix1 == '0.0'] = ''
首先想到使用np.empty()函数,如下:
matrix1=np.empty(shape=(31,22),dtype=str)
但是发现数组中每个元素仅保留单个字符,无法完整填入字符串。
于是更改使用np.zeros()函数,再将数据类型改为字符型,并将0值替换为空值,就得到了想要的空字符串数组。
matrix1=np.zeros(shape=(31,22)).astype(np.str_)
matrix1[matrix1 == '0.0'] = ''