다음 코드에 의해 생성 된 행렬이 있습니다numpy에서 문자열을 연결하는 방법 (백분율 생성)?
import numpy as np
table_vals = np.random.randn(4,4).round(4) * 100
와 나는이 같은 비율로 숫자를 변환하는 시도했다 :
>>> table_vals.astype(np.string_) + '%'
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')
과 같은 :
>>> np.str(table_vals) + '%'
"[[ 137.08 120.31 -55.73 43.6 ]\n [ -94.35 -105.27 -23.31 59.16]\n [-132.9 12.04 -36.69 106.52]\n [ 126.11 -91.38 -29.16 -138.01]]%"
그러나 그들 모두는 실패했다. 그래서 내가 무엇을해야하니?
이np.array([["%.2f%%" % number for number in row] for row in table_vals])
정말 멋지다! 고마워 ~ – DachuanZhao