span_tokenize gives generator object as output - nltk

I have written a simple piece of code to see exactly how the span_tokenize function works. Documentation for this can be found here: http://www.nltk.org/api/nltk.tokenize.html
Here is my piece of code
import nltk
from nltk.tokenize.api import StringTokenizer
sample = StringTokenizer()
sample.span_tokenize("Hulk is Boss")
The output is as follows:
<generator object StringTokenizer.span_tokenize at 0x113a7b258>
I can't understand why I am getting a generator object as an output when the expected output is tuple(int,int) as can be seen from nltk documentation
A nudge in the right direction is appreciated !!

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".

I am trying to Plot using Panels Widget FileInput?

I am trying to make a plotting system with a panel widget FileInput to also read yaml files. I get my buttons to functions and pick my files, but when I try to plot my files I get a TypeError: float() argument must be a string or a number, not 'FileInput'. I am put a sample of my code but not the files I am using on here. I could really use some help in what I am doing wrong. I am just starting to learn python widgets. Thanks in advance for any help I can get.
import matplotlib.pyplot as plt
import panel as pn
pn.extension()
year = 2006
model_path = pn.widgets.FileInput(multiple = True)
model_path
plot_control_file = pn.widgets.FileInput()
plot_control_file
plt.plot(model_path, plot_control_file)

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.

Unable to import react-native-vector-icons using es6

I'm trying to use react-native-vector-icons with ES6 in React Native, but unfortunately I'm having trouble importing the icons. Their documentation still uses the old require statement, so I don't think it's helpful.
This is my import:
import {Ionicons} from './node_modules/react-native-vector-icons/Ionicons.js';
This is my usage:
<Ionicons name="ios-book" color="#4F8EF7" />
The error I receive is:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
It's clear that Ionicons is undefined, so I'm aware that fundamental about the import statement is wrong.
import Ionicons from 'react-native-vector-icons/Ionicons';
import {x} from 'abc'; translates to var x=require('abc').x, not to var x=require('abc').
So what about :
import * as Ionicons from './node_modules/react-native-vector-icons/Ionicons.js';
I ended up using an import statement as follows:
import {default as Icon} from '../node_modules/react-native-vector-icons/Ionicons';
This is because after I followed #Olivier's advice, I ended up with an object that contained a number of properties and I couldn't just use <Icon> as a component, but I discovered that <Icon.default> worked.
Thanks to all who answered!

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