前提・実現したいこと
関数を初めて作ってい見たのですが
いまいちよく分かりません。
下記のコードの場合は、何がいけないのでしょうか?
該当のソースコード
#=========================================================================================== theta = math.radians(0) number_probe_xy = 21 width = 1 pitch_xy = (float(width)/(number_probe_xy-1)) ############################################################################################ ############################################################################################ #=========================================================================================== # # 座標計算の関数定義 # #=========================================================================================== def prob_locat (z): lst=[] for i in range(number_probe_xy): #上面(+y側の面) x = dec.Decimal((0.5 - pitch_xy*(i))*np.cos(theta)) - dec.Decimal((0.5)*np.sin(theta)) y = dec.Decimal((0.5 - pitch_xy*(i))*np.sin(theta)) + dec.Decimal((0.5)*np.cos(theta)) z = z lst += [x, y, z] #風上面 for i in range(number_probe_xy): x = dec.Decimal((-0.5)*np.cos(theta)) - dec.Decimal((0.5 - pitch_xy*(i))*np.sin(theta)) y = dec.Decimal((-0.5)*np.sin(theta)) + dec.Decimal((0.5 - pitch_xy*(i))*np.cos(theta)) z = z lst += [x, y, z] #下面(-y側の面) for i in range(number_probe_xy): x = dec.Decimal((-0.5 + pitch_xy*(i))*np.cos(theta)) - dec.Decimal((-0.5)*np.sin(theta)) y = dec.Decimal((-0.5 + pitch_xy*(i))*np.sin(theta)) + dec.Decimal((-0.5)*np.cos(theta)) z = z lst += [x, y, z] #風下面 for i in range(number_probe_xy): x = dec.Decimal((0.5)*np.cos(theta)) - dec.Decimal((-0.5 + pitch_xy*(i))*np.sin(theta)) y = dec.Decimal((0.5)*np.sin(theta)) + dec.Decimal((-0.5 + pitch_xy*(i))*np.cos(theta)) z = z lst += [x, y, z] ##上記のリストを3列にする関数 def convert_1d_to_2d(lst, cols): return [lst[i:i + cols] for i in range(0, len(lst), cols)] lst_reshape = convert_1d_to_2d(lst, 3) return lst_reshape test = [] test.append(prob_locat(0.5)) np.savetxt("test.csv", test, fmt='%s', delimiter=',')
発生している問題・エラーメッセージ
Traceback (most recent call last): File "locate_probe.py", line 74, in <module> np.savetxt("test.csv", test, fmt='%s', delimiter=',') File "<__array_function__ internals>", line 6, in savetxt File "/opt/anaconda3/2019.10/lib/python3.7/site-packages/numpy/lib/npyio.py", line 1 "Expected 1D or 2D array, got %dD array instead" % X.ndim) ValueError: Expected 1D or 2D array, got 3D array instead
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。