質問編集履歴

2

初めての質問で失礼しました。挿入いたしました。

2021/01/02 13:07

投稿

voigt
voigt

スコア1

test CHANGED
File without changes
test CHANGED
@@ -186,54 +186,6 @@
186
186
 
187
187
  ```
188
188
 
189
- import numpy as np
190
-
191
- from scipy import integrate
192
-
193
- from scipy.optimize import curve_fit
194
-
195
- import math
196
-
197
- import pandas as pd
198
-
199
-
200
-
201
- Eins = 2.01 * 10**8
202
-
203
-
204
-
205
- Lorentzbroad = Eins / 2 / math.pi
206
-
207
- widthL = Lorentzbroad / 10**9
208
-
209
-
210
-
211
- df = pd.read_csv('book1.csv')
212
-
213
- array_x=np.array(df['t'])
214
-
215
- array_y=np.array(df['y'])
216
-
217
-
218
-
219
- def func(x, param1, param2):
220
-
221
- def voigt(z):
222
-
223
- return param1 * 0.8256 / np.pi**(3/2) / param2 / widthL * np.exp((-1) * (2 * z / param2)**2 * np.log(2)) / (1 + (2 * (x - z) / widthL)**2)
224
-
225
- integration = integrate.quad(voigt, -np.inf, np.inf)[0]
226
-
227
- return integration
228
-
229
-
230
-
231
- p0 = 0.5, 0.5
232
-
233
- popt, pcov = curve_fit(func, array_x, array_y, p0)
234
-
235
-
236
-
237
189
  ### 試したこと
238
190
 
239
191
 

1

初めての質問で失礼しました。挿入いたしました。

2021/01/02 13:07

投稿

voigt
voigt

スコア1

test CHANGED
File without changes
test CHANGED
@@ -12,22 +12,146 @@
12
12
 
13
13
  ### 発生している問題・エラーメッセージ
14
14
 
15
+ ```
16
+
17
+ ---------------------------------------------------------------------------
18
+
19
+ TypeError Traceback (most recent call last)
20
+
21
+ <ipython-input-10-baa10670dc7d> in <module>
22
+
23
+ 21
24
+
25
+ 22 p0 = 0.5, 0.5
26
+
27
+ ---> 23 popt, pcov = curve_fit(func, array_x, array_y, p0)
28
+
29
+
30
+
31
+ ~\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in curve_fit(f, xdata, ydata, p0, sigma, absolute_sigma, check_finite, bounds, method, jac, **kwargs)
32
+
33
+ 750 # Remove full_output from kwargs, otherwise we're passing it in twice.
34
+
35
+ 751 return_full = kwargs.pop('full_output', False)
36
+
37
+ --> 752 res = leastsq(func, p0, Dfun=jac, full_output=1, **kwargs)
38
+
39
+ 753 popt, pcov, infodict, errmsg, ier = res
40
+
41
+ 754 cost = np.sum(infodict['fvec'] ** 2)
42
+
43
+
44
+
45
+ ~\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in leastsq(func, x0, args, Dfun, full_output, col_deriv, ftol, xtol, gtol, maxfev, epsfcn, factor, diag)
46
+
47
+ 381 if not isinstance(args, tuple):
48
+
49
+ 382 args = (args,)
50
+
51
+ --> 383 shape, dtype = _check_func('leastsq', 'func', func, x0, args, n)
52
+
53
+ 384 m = shape[0]
54
+
55
+ 385
56
+
57
+
58
+
59
+ ~\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in _check_func(checker, argname, thefunc, x0, args, numinputs, output_shape)
60
+
61
+ 24 def _check_func(checker, argname, thefunc, x0, args, numinputs,
62
+
63
+ 25 output_shape=None):
64
+
65
+ ---> 26 res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
66
+
67
+ 27 if (output_shape is not None) and (shape(res) != output_shape):
68
+
69
+ 28 if (output_shape[0] != 1):
70
+
71
+
72
+
73
+ ~\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in func_wrapped(params)
74
+
75
+ 456 if transform is None:
76
+
77
+ 457 def func_wrapped(params):
78
+
79
+ --> 458 return func(xdata, *params) - ydata
80
+
81
+ 459 elif transform.ndim == 1:
82
+
83
+ 460 def func_wrapped(params):
84
+
85
+
86
+
87
+ <ipython-input-10-baa10670dc7d> in func(x, param1, param2)
88
+
89
+ 17 def voigt(z):
90
+
91
+ 18 return param1 * 0.8256 / np.pi**(3/2) / param2 / widthL * np.exp((-1) * (2 * z / param2)**2 * np.log(2)) / (1 + (2 * (x - z) / widthL)**2)
92
+
93
+ ---> 19 integration = integrate.quad(voigt, -np.inf, np.inf)[0]
94
+
95
+ 20 return integration
96
+
97
+ 21
98
+
99
+
100
+
101
+ ~\Anaconda3\lib\site-packages\scipy\integrate\quadpack.py in quad(func, a, b, args, full_output, epsabs, epsrel, limit, points, weight, wvar, wopts, maxp1, limlst)
102
+
103
+ 339 if weight is None:
104
+
105
+ 340 retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
106
+
107
+ --> 341 points)
108
+
109
+ 342 else:
110
+
111
+ 343 retval = _quad_weight(func, a, b, args, full_output, epsabs, epsrel,
112
+
113
+
114
+
115
+ ~\Anaconda3\lib\site-packages\scipy\integrate\quadpack.py in _quad(func, a, b, args, full_output, epsabs, epsrel, limit, points)
116
+
117
+ 448 return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
118
+
119
+ 449 else:
120
+
121
+ --> 450 return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
122
+
123
+ 451 else:
124
+
125
+ 452 if infbounds != 0:
126
+
127
+
128
+
15
- only size-1 arrays can be converted to Python scalars
129
+ TypeError: only size-1 arrays can be converted to Python scalars
130
+
131
+ ```
132
+
133
+
16
134
 
17
135
 
18
136
 
19
137
  ### 該当のソースコード
20
138
 
139
+ ```python
140
+
21
141
  import numpy as np
22
142
 
23
143
  from scipy import integrate
24
144
 
25
145
  from scipy.optimize import curve_fit
26
146
 
147
+ import math
148
+
27
149
  import pandas as pd
28
150
 
29
151
 
30
152
 
153
+ Eins = 2.01 * 10**8
154
+
31
155
  Lorentzbroad = Eins / 2 / math.pi
32
156
 
33
157
  widthL = Lorentzbroad / 10**9
@@ -60,6 +184,54 @@
60
184
 
61
185
  popt, pcov = curve_fit(func, array_x, array_y, p0)
62
186
 
187
+ ```
188
+
189
+ import numpy as np
190
+
191
+ from scipy import integrate
192
+
193
+ from scipy.optimize import curve_fit
194
+
195
+ import math
196
+
197
+ import pandas as pd
198
+
199
+
200
+
201
+ Eins = 2.01 * 10**8
202
+
203
+
204
+
205
+ Lorentzbroad = Eins / 2 / math.pi
206
+
207
+ widthL = Lorentzbroad / 10**9
208
+
209
+
210
+
211
+ df = pd.read_csv('book1.csv')
212
+
213
+ array_x=np.array(df['t'])
214
+
215
+ array_y=np.array(df['y'])
216
+
217
+
218
+
219
+ def func(x, param1, param2):
220
+
221
+ def voigt(z):
222
+
223
+ return param1 * 0.8256 / np.pi**(3/2) / param2 / widthL * np.exp((-1) * (2 * z / param2)**2 * np.log(2)) / (1 + (2 * (x - z) / widthL)**2)
224
+
225
+ integration = integrate.quad(voigt, -np.inf, np.inf)[0]
226
+
227
+ return integration
228
+
229
+
230
+
231
+ p0 = 0.5, 0.5
232
+
233
+ popt, pcov = curve_fit(func, array_x, array_y, p0)
234
+
63
235
 
64
236
 
65
237
  ### 試したこと