小编wei*_*i14的帖子

使用空格分隔符连接多个 numpy 字符串数组

有没有办法将numpy 中的按元素字符串连接推广到 n > 2 种情况,并使用空格分隔符执行连接 " "。该np.char.add函数仅适用于 2 个数组,并且没有添加分隔符的选项。

import numpy as np

strings1 = np.array(["a", "b", "c"], dtype=np.str)
strings2 = np.array(["d", "e", "f"], dtype=np.str)
strings3 = np.array(["g", "h", "i"], dtype=np.str)

# Concatenate several string dtype arrays with a space delimiter
# I.e. something like strings1 + " " + strings2 + " " + strings3
# Code??
Run Code Online (Sandbox Code Playgroud)

期望:

array(['a d g', 'b e h', 'c f i'], dtype='<U5')
Run Code Online (Sandbox Code Playgroud)

python arrays string numpy

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

标签 统计

arrays ×1

numpy ×1

python ×1

string ×1