how do I get ipython to raise warnings everytime (repeated warnings) ? - warnings

I would like to import a module, use a function of that module and get a warning message every time the event that triggers the warning happens, not just the first time.
For example if I do (within ipython):
import scipy as sp
import matplotlib.pyplot as plt
x = sp.linspace(0,10)
plt.plot(x,1j*x)
I get the following warning:
/usr/lib/python2.7/dist-packages/numpy/core/numeric.py:320: ComplexWarning: Casting complex values to real discards the imaginary part return array(a, dtype, copy=False, order=order)
however, if I do
plt.plot(x,1j*x)
again, I don't get a warning message. As I said above, I would like to receive a warning message every time, not just the first time.
Thanks in advance.

I figured it out. Add
import warnings
warnings.filterwarnings('always')
before calling
plt.plot(x, 1j*x)

Related

How to plot a function in Python when both variables cannot be isolated to one side

I am trying to graph variable "u" versus variable "T" for 1<T<1000 (integers). However, the function I have includes both of the variables within an integral so I cannot create an isolated u=f(T) function. My thought process is to manipulate the function so that it is 0=f(T,u) and output a "u" value that minimizes f(T,u) for each T. However, I seem to be struggling a lot with how these variables and functions should be defined. All constants are defined and "E" should be defined through the integration step. The overall function I start with is:
5x10^28=integrate((pi/2)(8m/h^2)(E^0.5)(exp((E-u)/k*T)+1)^-1) from 0 to infinity and with respect to "E"
I am very new to python but the following code is how far I've been able to develop it based on previous forums and video tutorials. Any help is much appreciated!
from scipy.integrate import quad
import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize as spo
m=9.11e-31
h=6.63e-34
k=1.38e-23
T=list(range(1,1001))
def f(E,u):
return (np.pi/2)*(8*m/(h**2))*(E**0.5)*(1/((np.exp((E-u)/k*T)+1)))
Func_Equal_Zero=quad(f,0,np.inf,args=(u,))[0]-5e-28
Start_Guess_T_u=[500,1e-5]
result=spo.minimize(Func_Equal_Zero,Start_Guess_T_u)
plt.plot(T,u)
plt.figure(figsize=(6,6))
plt.xlabel('Temperature (k)')
plt.ylabel('Chemical Potential (J)')
I expected that I could just define the functions including "u" but python does not seem to like what I have tried. I am not sure if any of my other syntax is not correct because I cannot get past its issue with defining "u".

How to solve EfficientDet with Pytorch Runtime error?

I wanna training EfficientDet with PyTorch-Lightning,
but, i have a problem.
Most of those things were version error.
so, i matched version that model
from effdet.config.model_config import efficientdet_model_param_dict
from effdet import get_efficientdet_config, EfficientDet, DetBenchTrain
from effdet.efficientdet import HeadNet
from effdet.config.model_config import efficientdet_model_param_dict
when i imported effdet, i got runtime error like this
RuntimeError:
object has no attribute nms:
File "/home/ubuntu/anaconda3/envs/pytorch1.7.1_p37/lib/python3.7/site-packages/torchvision/ops/boxes.py", line 35
"""
_assert_has_ops()
return torch.ops.torchvision.nms(boxes, scores, iou_threshold)
~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
'nms' is being compiled since it was called from '_batched_nms_vanilla'
# Ideally for GPU we'd use a higher threshold
# keep only top max_det_per_image scoring predictions
batch_detections.append(detections)
return torch.stack(batch_detections, dim=0)
how to solve this problem?
i wanna modeling quickly...
also, this is version status

Why Bokeh has the following error msg?

I am trying to follow along the udemy tutorial and ran into the following error:
Bokeh Error
attempted to retrieve property value for property without value specification in the html by running the code below.
Does anyone have a clue as why it happened? Thanks!!
from bokeh.plotting import figure
from bokeh.io import output_file, show, gridplot
#from bokeh.sampledata.periodic_table import elements
from bokeh.models import Range1d, PanTool, ResetTool, HoverTool,
ColumnDataSource, LabelSet
import pandas
from bokeh.models.annotations import Span#assess object within
annotations
#prepare the output file
output_file("layout.html")
x1,y1=list(range(0,10)),list(range(10,20))
#create a new plot
f1=figure(width=250, plot_height=250, title="Circles")
f1.circle(x1, y1, size=10, color="navy", alpha=0.5)
#create a span annotation (a vertical reference line)
span_4=Span(location=4,dimension='height',line_color='grenn',
line_width=2)
#define where to add the span_4 object instance, add_layout method
f1.add_layout(span_4)
#create a box annotation
box_2_6=BoxAnnotation(left=2,right=6,fill_color="firebrick",
fill_alpha=0.3)
f1.add_layout(box_2_6)
#show the results
show(f1)
It appears to be because of a typo - line_color='grenn' should be line_color='green'. You're right that it's an unhelpful error message though. I'll try to open a GH issue about it.

How to import === in scalaz

I need to use the EqualsOps (===) from scalaz, but importing scalaz.Scalaz._ gives me a naming conflict with anorm's get method.
Here is the compilation error:
reference to get is ambiguous;
[error] it is imported twice in the same scope by
[error] import scalaz.Scalaz._
[error] and import anorm.SqlParser._
How can I bring === into scope without causing the conflict with anorm?
Remove import scalaz.Scalaz._
Assuming you are comparing primitives,
import scalaz._
import std.anyVal._
import syntax.equal._
If it is something else, say strings, replace std.anyVal._, with std.string._.
Essentially, the first line gives you the various scalaz types (if you don't want this, replace std with scalaz.std, and syntax with scalaz.syntax).
Line 2 gives you the implicit conversions for the primitives. That lets you treat primitives as Equal, or actually as any of the other scalaz typeclasses, (Monoid, etc.)
Line 3 gives you EqualOps, which enables you to use the === syntax with things that can be Equal.
Hope that helps

New to Python - proficient with Matlab: getting error "IndexError: list index out of range"

As the title says, I'm proficient with Matlab and already have this function written there and it works great. I wanted to learn a new language and I've been pointed to Python so I figured I would write a simple function to get used to the syntax of Python and have something to validate what I've done. I wrote the function "Xfcn" (which is non-dimensional mass flow in rocket problems) and it gives me the correct number if I only use one value. Now, I'd like to plot the X-function versus Mach and validate with my Matlab version. I need to loop through some Mach vector then plot it. Plotting comes later. I'm getting the error mentioned above and I think it's a simple indexing problem, although I can't seem to figure out what it is. I've looked here and on Python's documentation center so hopefully we can resolve this quickly. I've also checked the "type" of "i", printed the range(len(Ms)) and get 0-49, by 1's, as I expect with the particular values of Ms 0-1 by equally spaced increments, also as I expect, so I cannot figure out where my error is. My code is below.
from Xfcn import Xfcn
import pylab as pyl
import numpy as np
Ms = np.linspace(0,1,endpoint=True)
X = []
for i in range(len(Ms)):
X[i][0] = Xfcn(Ms[i])
print X
print 'Done.'
Thanks for the help!
BL
You created x as a single dimensional list and are trying to access it as if it was multi dimensional