在numpy的元素明智的字符串连接 [英] Element-wise string concatenation in numpy

查看:1435
本文介绍了在numpy的元素明智的字符串连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个错误吗?

import numpy as np
a1=np.array(['a','b'])
a2=np.array(['E','F'])

In [20]: add(a1,a2)
Out[20]: NotImplemented

我试图做逐元素字符串连接。我想加入()是做在numpy的方式,但显然预期它不工作。

I am trying to do element-wise string concatenation. I thought Add() was the way to do it in numpy but obviously it is not working as expected.

推荐答案

这可以用做<一个href=\"http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.core.defchararray.add.html\">numpy.core.defchararray.add.下面是一个例子:

This can be done using numpy.core.defchararray.add. Here is an example:

>>> import numpy as np
>>> a1 = np.array(['a', 'b'])
>>> a2 = np.array(['E', 'F'])
>>> np.core.defchararray.add(a1, a2)
array(['aE', 'bF'], 
      dtype='<U2')

有其他有用的字符串操作使用为numpy的数据类型。

There are other useful string operations available for NumPy data types.

这篇关于在numpy的元素明智的字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆