I would like to use scipy's integrate.simps to get a integrated function from a data sample.
Data sample is getting calculated inside For loop (variable fx).
In the same step I store integrated values in the variable intfx.
import numpy as np
import pylab as pl
from scipy import integrate
t=np.arange(0,10.01,0.01)
fx=[]
intfx=[]
counter=0
for i in t:
counter+=1
fx.append(np.sin(i))
intfx.append(fx[-1]+integrate.trapz(fx[-2:], dx=0.1))
pl.plot(t,fx)
pl.plot(t,intfx)
pl.show()
On plots it can be seen that the two functions are very similar, which is obviously wrong.
Can anyone help me with this?
Made a stupid mistake.
Line:
intfx.append(fx[-1]+integrate.trapz(fx[-2:], dx=0.1))
should look like this:
intfx.append(intfx[-1]+integrate.trapz(fx[-2:], dx=0.1))
Related
I'm trying to tree shale chart.js with vue3 but dont know what i'm doing, I currently import the whole chart.js using: import Chart from 'chart.js/auto' but how can i import only the needed bits , so as to make ny build smaller?
as stated in the docs here you need to import and register all the elements you are using:
import {Chart, DoughnutController, ArcElement} from 'chart.js';
Chart.register(DoughnutController, ArcElement)
Instead of importing the DoughnutController and ArcElement you need to import and register the elements you are using.
Hi im getting this issue and can't quite figure why its saying it. im using vue3 with tailwind.
""export 'default' (imported as 'Chart') was not found in 'chart.js'"
Guess you are trying to import chart.js like this import Chart from 'chart.js', since chart.js v3 chart.js is treeshakable so you will have to import and register all the components you want to use or import and register everything with the auto import like this: import Chart from 'chart.js/auto'
Docs: https://www.chartjs.org/docs/master/getting-started/integration.html#bundlers-webpack-rollup-etc
For me, I just had to downgrade from chart.js#3.x to chart.js#2.9.4
I am following the XRD plot tutorial and as it told in this tutorial I imported
from pymatgen import Lattice, Structure
from pymatgen.analysis.diffraction.xrd import XRDCalculator
from IPython.display import Image, display
%matplotlib inline
And after defining the structure I try to plot it with these commands
c = XRDCalculator()
c.show_xrd_plot(structure)
But I bump into this error: 'no attribute 'show_xrd_plot'
AttributeError: 'XRDCalculator' object has no attribute 'show_xrd_plot'
What should I do to make it work, many thanks in advance,
Happy Thanksgiving
The XRD tutorial of pymatgen is updated and xrd_show_plot it changed to
c.show_plot(structure)
I decided to use mttkinter in my project, but I have problem. I usually import tkinter like this:
from tkinter import *
root=Tk()
And I tried mttkinter like this import:
from mttkinter import *
root=Tk()
After this, I saw global name 'Tk' is not defined.
What can I do with it?
I know this is a old question, but I had the same problem and found a solution.
As stated in the comments you're probably using Python 3.x. since you use "tkinter" all in lower case.
If you check the example from the mtTkinter github.
You'll see that the example checks for the Python version installed and imports either "Tkinter" or "tkinter" before importing mtTkinter (I would assume, to make sure you have access to everything in tkinter even if mtTkinter is not up to date).
For your case (as for mine), your imports should be:
from tkinter import *
from mttkinter import mtTkinter
root = Tk()
Note that if we read what's in the code, your import should work, but you'd have to declare root as follows (I tested this import and it works):
from mttkinter import *
root = mtTkinter.Tk()
Again, I know this question is old, but the answer might be useful for someone else.
Cheers.
I am using IPython, which is downloaded from "Enthought Python Distribution"
Under IPython / Python 2.7.3, when I type help(__doc__), the result is:
In [26]: help(__doc__)
no Python documentation found for 'Automatically created module for IPython interactive environment'
What is the meaning of this result? IPython does not support?
Thanks!
As #Blender says, __doc__ is just a string, and is usually the help string for a given function or module. For example,
In [1]: numpy.__doc__
Out[1]: '\nNumPy\n=====\n\nProvides\n 1. An array object of arbitrary homogeneous items\n 2. Fast mathematical operations over arrays\n ...
is the help string for the numpy module. Calling help() on numpy essentially just prints out a nicely formatted version of this string:
Help on package numpy:
NAME
numpy
FILE
/usr/lib64/python2.6/site-packages/numpy/__init__.py
DESCRIPTION
NumPy
=====
Provides
1. An array object of arbitrary homogeneous items
2. Fast mathematical operations over arrays
...
In IPython, the string __doc__ is just:
In [3]: __doc__
Out[3]: 'Automatically created module for IPython interactive environment'
Calling help(__doc__) then looks for __doc__.__doc__, which doesn't exist.