Created
June 9, 2014 04:22
-
-
Save mkacky/f3e9cd1d68701c550c6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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