Skip to content

Instantly share code, notes, and snippets.

@mkacky
Created June 9, 2014 04:28
Show Gist options
  • Save mkacky/a23140d4d5928ad73309 to your computer and use it in GitHub Desktop.
Save mkacky/a23140d4d5928ad73309 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)
## stringからobjectにキャスト
objArray = strArray.astype(object)
## 数字(文字列)の配列を用意
strNumArray = np.arange(num).astype(str)
## intからobjectにキャスト
objNumArray = strNumArray.astype(object)
## 要素のobject同士を結合してから、strにキャストする
combinedArray = np.add(objArray, objNumArray).astype(str)
# 表示例
# >>> combinedArray
# array(['-0', '-1', '-2'],
# dtype='|S2')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment