Skip to content

Instantly share code, notes, and snippets.

@mkacky
Created June 9, 2014 04:22
Show Gist options
  • Save mkacky/f3e9cd1d68701c550c6d to your computer and use it in GitHub Desktop.
Save mkacky/f3e9cd1d68701c550c6d to your computer and use it in GitHub Desktop.
#! /usr/bin/python
# -*- coding: utf-8 -*-
import numpy as np
num = 3
## "-"という文字列を要素に持つ配列を用意
strArray = np.array(["-"] * num)
## 数字(文字列)の配列を用意
strNumArray = np.arange(num).astype(str)
## 要素の文字列同士を結合する
combinedArray = np.core.defchararray.add(strArray, strNumArray)
# 表示例
# >>> combinedArray
# array(['-0', '-1', '-2'],
# dtype='|S25')
## 以下は意図した結果にならない
combinedArray = np.add(strArray, strNumArray)
# 表示例
# >>> combinedArray
# NotImplemented
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment