How do I integrate a Gaussian using Scipy? [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I can't think of what I might be doing wrong: This is the code I've been using, followed by the error I'm getting (thanks in advance for your time):
import scipy.integrate
import numpy as np
integrand= lambda x:((x**1)*(np.exp((-1*(x - 5)**2) / (2 * 10**2)))
intmom = scipy.integrate.quad(integrand, 1, 10)
print(intmom)
Error:
File "", line 3
intmom = scipy.integrate.quad(integrand, 1, 10)
^
SyntaxError: invalid syntax

You are missing a closing ) on the previous line it should be
integrand= lambda x:((x**1)*(np.exp((-1*(x - 5)**2) / (2 * 10**2))))
Output:
(47.53743192883985, 5.277715145894907e-13)

Related

A python syntax error that cannot find and answer [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
def calculate_money_made(**trips):
total_money_made = 0
for trip_id, trip from trips.items():
trip_revenue = trip.cost - trip.driver.cost
total_money_made += trip_revenue
return total_money_made
gives an error! cannot figure out
File "script.py", line 41
for trip_id, trip from trips.items():
^
SyntaxError: invalid syntax
Change "from" to "in"
for trip_id, trip in trip.items():

What can I do to fix this Syntax Error if I put everything in correctly? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
def infPi(num):
pi = 0
for i in range(num):
pi += (1/((2(i+1)-1)**2)
print(pi*4)
The syntax error is for the line with "Print(pi*4)"
There was a parenthesis missing at the end and a syntax error in the 4th line ( pi += (1/(2*(i+1)-1)**2) ) , try like this:
def infPi(num):
pi = 0
for i in range(num):
pi += (1/(2*(i+1)-1)**2)
print(pi*4)

Python parentheses mistake (?) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
When I run this code
from numpy import linspace,arange
from pylab import plot, show
T=1.05
pp=[]
nn=[]
for V in arange (1,50):
P=(8*T)/(3*V-1)-3/(V**2)
a=((V-1/3)*(8/3)*(V**2))/((8/3)*T*(V**3)-6(V-1/3)**2)
pp.append(P)
nn.append(a)
plot(P,a)
show()
I get:
File "C:\Users\asus\Desktop\", line 8, in <module>
a=((V-1/3)*(8/3)*(V**2))/((8/3)*T*(V**3)-6(V-1/3)**2)
TypeError: 'int' object is not callable
And I don't know why.
Issue is in line -
a=((V-1/3)*(8/3)*(V**2))/((8/3)*T*(V**3)-6(V-1/3)**2)
You are using 6(V-1/3) , you need to use - 6*(V-1/3) , as -
a=((V-1/3)*(8/3)*(V**2))/((8/3)*T*(V**3)-6*(V-1/3)**2)

Indentation error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I receive an indentation error that I cannot figure out the reason.
The error is
('unexpected indent', ('C:/Hamid/Failure_index.py',15,1,'\tSDV2=xyList[0]\n')).
My code is
from abaqusConstants import *
from odbAccess import *
from visualization import *
#---------------------------------------------------------------------------
out_file= 'C:\Hamid\Stochastic\Python_script_for_Monte_Carlo_simulation\Microtensile/Failure_index.dat'
fid = open(out_file,'w')
for i in range(1,50):
odb_path = 'C:\Hamid\Stochastic\Python_script_for_Monte_Carlo_simulation\Microtensile/Microtens-'+str(i)+'_xs.odb'
session.openOdb(name=odb_path)
odb = session.odbs[odb_path]
session.viewports['Viewport: 1'].setValues(displayedObject=odb)
xyList = session.xyDataListFromField(odb=odb, outputPosition=INTEGRATION_POINT, variable=(('SDV2', INTEGRATION_POINT), ), elementSets=(' ALL ELEMENTS', ))
SDV2 = xyList[0]
fid.write(SDV2+'\n')
odb.close()
fid.close()
You are mixing tabs and spaces in your source code, and Python's algorithm for expanding tabs to spaces causes SDV2 = xyList[0] to be indented 8 spaces, not 4 like the other lines in the for loop.

python3-invalid syntax on a line that do not exist [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
python3-invalid syntax error
File "6_1.py", line 8
SyntaxError: invalid syntax
But there is no line 8. So what is the problem.
import zipfile,re
with ZipFile('../../下载/channel.zip') as myzip:
nothing = '90052'
rex = re.compile(r'\d+')
while True:
print(myzip.getinfo(nothing+'txt'))
nothing = re.findall(rex, myzip.open(nothing+'txt')[0]
No, but Python thinks there should be because line 7 is not complete:
nothing = re.findall(rex, myzip.open(nothing+'txt')[0]
# open 1 -------- open 2 ----- close 2 - ^ where is close 1?
There is a closing ) missing at the end.

Categories