質問編集履歴
3
質問の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,135 +1,34 @@
|
|
1
|
+
numpyブロードキャストエラーの原因について教えてください.
|
1
|
-
下記の
|
2
|
+
下記のようなエラーです.
|
3
|
+
ValueError: operands could not be broadcast together with shapes (21,) (51,)
|
4
|
+
|
2
5
|
```python
|
6
|
+
import numpy as np
|
3
7
|
import math
|
4
|
-
import numpy as np
|
5
|
-
print('平面応力状態(半無限平板)')
|
6
8
|
|
7
9
|
Pn = 2200
|
8
10
|
z_depth = 5
|
9
11
|
π = math.pi
|
10
|
-
y=1
|
11
12
|
|
12
|
-
z = np.arange(0,(z_depth+0.1)*10)/10
|
13
|
-
|
14
|
-
σy_heimen = (-2*Pn*(z**3))/(π*(((y**2)+(z**2)))**2)
|
15
|
-
|
16
|
-
for σy_heimen1,z1 in zip(σy_heimen,z):
|
17
|
-
print(f'σy={σy_heimen1:.6f},z={z1:.6f}')
|
18
|
-
```
|
19
|
-
下写真表示されるが,
|
20
|
-

|
21
|
-
下の通り,作成中のプログラムに組み込むと,
|
22
|
-
File "E:\9.内部応力解析プログラム\内部応力分布.py", line 115, in <module>
|
23
|
-
σy_heimen = (-2*Pn*(z**3))/(π*(((y**2)+(z**2)))**2)
|
24
|
-
ValueError: operands could not be broadcast together with shapes (21,) (51,)
|
25
|
-
というエラーが出ます.numpyのブロードキャストについて調べましたが,わかりませんでした.
|
26
|
-
エラーをなくす方法を教えてください.
|
27
|
-
|
28
|
-
```python
|
29
|
-
|
30
|
-
while True:
|
31
|
-
print('最大接触応力(MPa)は?')#各数値入力
|
32
|
-
Pmax= float(input('>> '))
|
33
|
-
|
34
|
-
print('摩擦係数は?')
|
35
|
-
μ= float(input('>> '))
|
36
|
-
|
37
|
-
print('試験ローラ半径(mm)は?')
|
38
|
-
R1= float(input('>> '))
|
39
|
-
|
40
|
-
print('相手ローラ半径(mm)は?')
|
41
|
-
R2= float(input('>> '))
|
42
|
-
|
43
|
-
print('試験ローラのヤング率(GPa)は?')
|
44
|
-
E1= float(input('>> '))
|
45
|
-
|
46
|
-
print('相手ローラのヤング率(GPa)は?')
|
47
|
-
E2= float(input('>> '))
|
48
|
-
|
49
|
-
print('試験ローラのポアソン比は?')
|
50
|
-
ν1= float(input('>> '))
|
51
|
-
|
52
|
-
print('相手ローラのポアソン比は?')
|
53
|
-
ν2= float(input('>> '))
|
54
|
-
|
55
|
-
print('二円筒の接触幅(mm)は?')
|
56
|
-
b= float(input('>> '))
|
57
|
-
|
58
|
-
print('内部応力評価深さ(mm)は?')
|
59
|
-
z_depth= float(input('>> '))
|
60
|
-
|
61
|
-
print('最大接触応力(MPa)=',Pmax) #数値確認
|
62
|
-
print('摩擦係数=',μ)
|
63
|
-
print( '試験ローラ半径(mm)=',R1)
|
64
|
-
print( '相手ローラ半径(mm)=',R2)
|
65
|
-
print('試験ローラのヤング率(GPa)=',E1)
|
66
|
-
print('相手ローラのヤング率(GPa)=',E2)
|
67
|
-
print('試験ローラのポアソン比=',ν1)
|
68
|
-
print('相手ローラのポアソン比=',ν2)
|
69
|
-
print('二円筒の接触幅(mm)=',b)
|
70
|
-
print('内部応力評価深さ(mm)=',z_depth)
|
71
|
-
|
72
|
-
|
73
|
-
|
13
|
+
########ここでエラーがでていると思います############
|
74
|
-
|
14
|
+
################################################
|
75
|
-
|
76
|
-
num = float(input('>>'))
|
77
|
-
|
78
|
-
if int(num) == 999:
|
79
|
-
|
80
|
-
print('計算を開始します')
|
81
|
-
break
|
82
|
-
|
83
|
-
print('数値を再入力してください')
|
84
|
-
|
85
|
-
#計算開始or数値再入力
|
86
|
-
|
87
|
-
import math,cmath #math,cmathモジュールをインポート
|
88
|
-
|
89
|
-
π = math.pi #π定義
|
90
|
-
|
91
|
-
Pn = (Pmax**2)*π*b*R1*R2*(E2*(1-ν1**2)+E1*(1-ν2**2))*(10**(-3))/((R1+R2)*E1*E2)
|
92
|
-
|
93
|
-
#Pn = (π*(-b)*E2*(Pmax**2)*R1*R2*(ν1**2)+π*b*E2*(Pmax**2)*R1*R2-E1*π*b*(Pmax**2)*R1*R2*(ν2**2)+E1*π*b*(Pmax**2)*R1*R2)/(1000*(E1*E2*(R1+R2)))
|
94
|
-
|
95
|
-
print('Pn(N)=',Pn)
|
96
|
-
|
97
|
-
c = (4*Pn*R1*R2*(E2*(1-ν1**2)+E1*(1-ν2**2))/(1000*(π*b*E1*E2*(R1+R2))))**(0.5)
|
98
|
-
|
99
|
-
print('c(mm)=',c)
|
100
|
-
|
101
|
-
#Pn,cが求めれた
|
102
|
-
|
103
|
-
import numpy as np
|
104
|
-
#numpyモジュールインポート
|
105
|
-
|
106
15
|
y_c = np.arange(-10, 11) / 10 #初項-10,終点11の等差数列
|
107
|
-
|
16
|
+
c=0.5
|
108
17
|
y = y_c*c
|
18
|
+
################################################
|
109
19
|
|
110
|
-
p = Pmax*((1-y_c**2)**(0.5))
|
111
|
-
|
112
|
-
q = μ*Pmax*((1-y_c**2)**(0.5))
|
113
|
-
#p = Pmax*((1-(y/c)**2))**(0.5)
|
114
|
-
#q = μ*Pmax*((1-(y/c)**2))**(0.5)
|
115
|
-
|
116
|
-
for n,m,p_y,q_y in zip(y,y_c,p,q):
|
117
|
-
print(f'y={n:.6f}(mm),y/c={m:.6f},p(y)={p_y:.6f}(MPa),q(y)={q_y:.6f}(MPa)')
|
118
|
-
|
119
|
-
#########################################################################
|
120
|
-
#ここまでエラーなし
|
121
|
-
########################################################################
|
122
|
-
#平面応力状態(半無限平板)でのσy,σz,τyzを求める.
|
123
20
|
print('平面応力状態(半無限平板)')
|
124
21
|
|
125
22
|
z = np.arange(0,(z_depth+0.1)*10)/10 #z決定
|
126
23
|
|
24
|
+
|
127
25
|
σy_heimen = (-2*Pn*(y**2)*z)/(π*(((y**2)+(z**2)))**2)
|
128
26
|
σz_heimen = (-2*Pn*(z**3))/(π*(((y**2)+(z**2)))**2)
|
129
27
|
τyz_heimen = (-2*Pn*(z**2)*y)/(π*(((y**2)+(z**2)))**2)
|
28
|
+
for σy_heimen1,σz_heimen1,τyz_heimen1,z1 in zip(σy_heimen,σz_heimen,τyz_heimen,z):
|
29
|
+
print(f'σy={σy_heimen1:.6f},σz={σz_heimen1:.6f},τyz={τyz_heimen1:.6f},z={z1:.6f}')
|
130
30
|
|
131
|
-
|
31
|
+
|
132
|
-
print(f'σy={σy_heimen1:.6f},z={z1:.6f}')
|
133
|
-
|
134
32
|
input()
|
33
|
+
|
135
34
|
```
|
2
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -26,16 +26,110 @@
|
|
26
26
|
エラーをなくす方法を教えてください.
|
27
27
|
|
28
28
|
```python
|
29
|
+
|
30
|
+
while True:
|
31
|
+
print('最大接触応力(MPa)は?')#各数値入力
|
32
|
+
Pmax= float(input('>> '))
|
33
|
+
|
34
|
+
print('摩擦係数は?')
|
35
|
+
μ= float(input('>> '))
|
36
|
+
|
37
|
+
print('試験ローラ半径(mm)は?')
|
38
|
+
R1= float(input('>> '))
|
39
|
+
|
40
|
+
print('相手ローラ半径(mm)は?')
|
41
|
+
R2= float(input('>> '))
|
42
|
+
|
43
|
+
print('試験ローラのヤング率(GPa)は?')
|
44
|
+
E1= float(input('>> '))
|
45
|
+
|
46
|
+
print('相手ローラのヤング率(GPa)は?')
|
47
|
+
E2= float(input('>> '))
|
48
|
+
|
49
|
+
print('試験ローラのポアソン比は?')
|
50
|
+
ν1= float(input('>> '))
|
51
|
+
|
52
|
+
print('相手ローラのポアソン比は?')
|
53
|
+
ν2= float(input('>> '))
|
54
|
+
|
55
|
+
print('二円筒の接触幅(mm)は?')
|
56
|
+
b= float(input('>> '))
|
57
|
+
|
58
|
+
print('内部応力評価深さ(mm)は?')
|
59
|
+
z_depth= float(input('>> '))
|
60
|
+
|
61
|
+
print('最大接触応力(MPa)=',Pmax) #数値確認
|
62
|
+
print('摩擦係数=',μ)
|
63
|
+
print( '試験ローラ半径(mm)=',R1)
|
64
|
+
print( '相手ローラ半径(mm)=',R2)
|
65
|
+
print('試験ローラのヤング率(GPa)=',E1)
|
66
|
+
print('相手ローラのヤング率(GPa)=',E2)
|
67
|
+
print('試験ローラのポアソン比=',ν1)
|
68
|
+
print('相手ローラのポアソン比=',ν2)
|
69
|
+
print('二円筒の接触幅(mm)=',b)
|
70
|
+
print('内部応力評価深さ(mm)=',z_depth)
|
71
|
+
|
72
|
+
|
73
|
+
print('上記の数値でよろしいですか?')
|
74
|
+
print('よろしければ999を,修正の場合は適当な数字を入力してください')
|
75
|
+
|
76
|
+
num = float(input('>>'))
|
77
|
+
|
78
|
+
if int(num) == 999:
|
79
|
+
|
80
|
+
print('計算を開始します')
|
81
|
+
break
|
82
|
+
|
83
|
+
print('数値を再入力してください')
|
84
|
+
|
85
|
+
#計算開始or数値再入力
|
86
|
+
|
87
|
+
import math,cmath #math,cmathモジュールをインポート
|
88
|
+
|
89
|
+
π = math.pi #π定義
|
90
|
+
|
91
|
+
Pn = (Pmax**2)*π*b*R1*R2*(E2*(1-ν1**2)+E1*(1-ν2**2))*(10**(-3))/((R1+R2)*E1*E2)
|
92
|
+
|
93
|
+
#Pn = (π*(-b)*E2*(Pmax**2)*R1*R2*(ν1**2)+π*b*E2*(Pmax**2)*R1*R2-E1*π*b*(Pmax**2)*R1*R2*(ν2**2)+E1*π*b*(Pmax**2)*R1*R2)/(1000*(E1*E2*(R1+R2)))
|
94
|
+
|
95
|
+
print('Pn(N)=',Pn)
|
96
|
+
|
97
|
+
c = (4*Pn*R1*R2*(E2*(1-ν1**2)+E1*(1-ν2**2))/(1000*(π*b*E1*E2*(R1+R2))))**(0.5)
|
98
|
+
|
99
|
+
print('c(mm)=',c)
|
100
|
+
|
101
|
+
#Pn,cが求めれた
|
102
|
+
|
103
|
+
import numpy as np
|
104
|
+
#numpyモジュールインポート
|
105
|
+
|
106
|
+
y_c = np.arange(-10, 11) / 10 #初項-10,終点11の等差数列
|
107
|
+
|
108
|
+
y = y_c*c
|
109
|
+
|
110
|
+
p = Pmax*((1-y_c**2)**(0.5))
|
111
|
+
|
112
|
+
q = μ*Pmax*((1-y_c**2)**(0.5))
|
113
|
+
#p = Pmax*((1-(y/c)**2))**(0.5)
|
114
|
+
#q = μ*Pmax*((1-(y/c)**2))**(0.5)
|
115
|
+
|
116
|
+
for n,m,p_y,q_y in zip(y,y_c,p,q):
|
117
|
+
print(f'y={n:.6f}(mm),y/c={m:.6f},p(y)={p_y:.6f}(MPa),q(y)={q_y:.6f}(MPa)')
|
118
|
+
|
119
|
+
#########################################################################
|
120
|
+
#ここまでエラーなし
|
121
|
+
########################################################################
|
29
122
|
#平面応力状態(半無限平板)でのσy,σz,τyzを求める.
|
30
123
|
print('平面応力状態(半無限平板)')
|
31
|
-
#Pn,π,z_depth,yをこれより前で決定しています.
|
32
124
|
|
33
|
-
import numpy as py
|
34
|
-
import math
|
35
125
|
z = np.arange(0,(z_depth+0.1)*10)/10 #z決定
|
36
126
|
|
127
|
+
σy_heimen = (-2*Pn*(y**2)*z)/(π*(((y**2)+(z**2)))**2)
|
37
|
-
σ
|
128
|
+
σz_heimen = (-2*Pn*(z**3))/(π*(((y**2)+(z**2)))**2)
|
129
|
+
τyz_heimen = (-2*Pn*(z**2)*y)/(π*(((y**2)+(z**2)))**2)
|
38
130
|
|
39
131
|
for σy_heimen1,z1 in zip(σy_heimen,z):
|
40
132
|
print(f'σy={σy_heimen1:.6f},z={z1:.6f}')
|
133
|
+
|
134
|
+
input()
|
41
135
|
```
|
1
誤字
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
【python】numpy
|
1
|
+
【python】numpy ブロードキャストエラー
|
body
CHANGED
File without changes
|