I try to use the output format of sympy in spyder in a script. I would like to understand how to activate and deactivate the format without changing the console to reset everything.
The format I would like to achieve is something like this: "[Out2]" is what I'd like to achieve.
Code suggestions which don't work for me
I have tried these so far:
import sympy as sym
x= sym.symbols("x")
sym.init_session(quiet=True)
print(sym.Integral(sym.sqrt(1/x),x))
or
from IPython.display import display
display(sym.Integral(sym.Integral(sym.sqrt(1/x),x))
or
sym.init_printing()
sym.pprint(sym.Integral(sym.sqrt(1/x),x))
I just can achieve something like this:
this format is not what I try to achieve.
Related
I'm a beginner in Dart. I want to write a program that takes an input and print it with some predefined text.
This is how my code looks like:
import 'dart:convert';
import 'dart:io';
main() {
print('What is your name?');
print('Hello ${stdin.readLineSync(encoding: utf8)}');
}
And this is the how the command line looks like:
What is your name?
Leó Takács
Hello Le Takcs
It's just delete all the special characters. I think the problem is with the readLineSync because I tried printing 'Leó' and it works that way. My Dart SDK version is 2.14.2 by the way.
Thanks for your help!
It works for me (on Linux in an rxvt-unicode terminal).
That suggests that the problem isn't necessarily in the Dart platform code, or at least it's platform specific.
What platform are you running on?
What console are you using?
Is the console in fact UTF-8, or is it Latin-1 or Windows-1252? Try changing to encoding: latin1 and see if it makes a difference.
I'm using Konva in a Vue application, and I can't suppress Konva's warnings in browser console.
According to Konva docs, there is an option for this, Konva.showWarnings = false. (I understood the warning itself and am aware of its possible implications).
I've checked this: Turn off Konvajs warnings, but to no avail, the answer here just explains that such a setting exists.
What I'm doing in my main.js file:
import VueKonva from 'vue-konva'
Vue.use(VueKonva)
and then I'm trying to apply the setting:
VueKonva.showWarnings = false
I've also tried adding it inside Vue.use as option:
Vue.use(VueKonva, {showWarnings: false})
...but to no avail.
What am I missing here?
You should do the same:
import Konva from 'konva';
Konva.showWarnings = false;
Are you sure you want to disable them?
edited: as the final solution to the problem, I'm adding #lavrton's comment from below:
For the showWarnings property to work in vue-konva, you need to import both the original konva library, and the vue one for vue-bindings.
The working code now looks like this:
import VueKonva from "vue-konva";
import Konva from "konva";
Konva.showWarnings = false;
Vue.use(VueKonva);
Vue.use(Konva);
I am currently using jupyter-manim since it is the most efficient way for me to use manim. I'm running my code on Kaggle and every time I use TextMobject in manim, it outputs an error that says Latex error converting to dvi. See log output above or the log file: media/Tex/54dfbfee288272f0.log. I've tried TexMobject and Text function, but only the Text function works. The Text function is limited however, and I'm not sure how to change the font. Is there a way to fix this or is it something that comes with using jupyter-manim? It seems that all the other functions work such as drawing shapes, animating scenes, etc.
%%manim
class Text(Scene):
def construct(self):
first_line = TextMobject('Hi')
second_line = TexMobject('Hi')
#Only one that works
third_line = Text('Hi')
I tried your Manim program and it worked as expected for me. I would try making sure
include from manimlib.imports import * in your first line (importing Manim library)
include self.play(...) so you can see them
I think you already have these, but I'm putting them in case you don't.
You may also be getting the error because you do not have a LaTeX distribution installed on your system (i.e. MikTex or Texlive).
I think part of your problem may be the name of the class you chose. I had problems with your code until I changed the name from Text to TextTest. Here is a minimally working example that works fine in my Jupyter notebook (after running import jupyter_manim of course).
%%manim TextTest -p -ql
from manim import *
class TextTest(Scene):
def construct(self):
first_line = TextMobject('Hi 1')
second_line = TexMobject('Hi 2').shift(DOWN)
third_line = Text('Hi 3').shift(UP)
self.add(first_line)
self.add(second_line)
self.add(third_line)
self.wait(1)
Also, you should be aware that TextMobject and TexMobject have been deprecated.
I am using the following code but I am not able to extract any information from the url.
from urllib.parse import urlparse
if __name__ == "__main__":
z = 5
url = 'https://twitter.com/isro/status/1170331318132957184'
df = urlparse(url)
print(df)
ParseResult(scheme='https', netloc='twitter.com', path='/isro/status/1170331318132957184', params='', query='', fragment='')
I was hoping to extract the tweet message, time of tweet and other information available from the link but the code above clearly doesn't achieve that. How do I go about it from here ?
print(df)
ParseResult(scheme='https', netloc='twitter.com', path='/isro/status/1170331318132957184', params='', query='', fragment='')
I think you may be misunderstanding the purpose of the urllib parseurl function. From the Python documentation:
urllib.parse.urlparse(urlstring, scheme='', allow_fragments=True)
Parse a URL into six components, returning a 6-item named tuple. This
corresponds to the general structure of a URL:
scheme://netloc/path;parameters?query#fragment
From the result you are seeing in ParseResult, your code is working perfectly - it is breaking your URL up into the component parts.
It sounds as though you actually want to fetch the web content at that URL. In that case, I might take a look at urllib.request.urlopen instead.
I am using Google's Colaboratory platform to run python in a Jupyter notebook. In standard Jupyter notebooks, the output of sympy functions is correctly typeset Latex, but the Colaboratory notebook just outputs the Latex, as in the following code snippet:
import numpy as np
import sympy as sp
sp.init_printing(use_unicode=True)
x=sp.symbols('x')
a=sp.Integral(sp.sin(x)*sp.exp(x),x);a
results in Latex output like this:
$$\int e^{x} \sin{\left (x \right )}\, dx$$
The answer cited in these questions, Rendering LaTeX in output cells in Colaboratory and LaTeX equations do not render in google Colaboratory when using IPython.display.Latex doesn't fix the problem. While it provides a method to display Latex expressions in the output of a code cell, it doesn't fix the output from the built-in sympy functions.
Any suggestions on how to get sympy output to properly render? Or is this a problem with the Colaboratory notebook?
I have just made this code snippet to make sympy works like a charm in colab.research.googlr.com !!!
def custom_latex_printer(exp,**options):
from google.colab.output._publish import javascript
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default"
javascript(url=url)
return sympy.printing.latex(exp,**options)
init_printing(use_latex="mathjax",latex_printer=custom_latex_printer)
Put it after you imported sympy
This one basically tell sympy to embed mathjax library using colab api before they actually output any syntax.
You need to include MathJax library before display. Set it up in a cell like this first.
from google.colab.output._publish import javascript
url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=default"
Later, you include javascript(url=url) before displaying:
x=sp.symbols('x')
a=sp.Integral(sp.sin(x)*sp.exp(x),x)
javascript(url=url)
a
Then, it will display correctly.
Using colab's mathjax and setting the configuration file to TeX-MML-AM_HTMLorMML worked for me. Below is the code:
from sympy import init_printing
from sympy.printing import latex
def colab_LaTeX_printer(exp, **options):
from google.colab.output._publish import javascript
url_ = "https://colab.research.google.com/static/mathjax/MathJax.js?"
cfg_ = "config=TeX-MML-AM_HTMLorMML" # "config=default"
javascript(url=url_+cfg_)
return latex(exp, **options)
# end of def
init_printing(use_latex="mathjax", latex_printer=colab_LaTeX_printer)