I am trying to print a scipy result with pretty print but it seems output not in latex format.
import sympy
from sympy import *
init_printing()
var('x,y')
y = sympy.expand((x+y)**2)
y
Output:
Make sure you are using the latest version of SymPy (0.7.6.1). There was an issue with printing which was fixed in the 0.7.6.1 bugfix release.
You need set pretty printing up:
from sympy import init_printing
init_printing()
Now it should work.
Also install matplotlib.
Related
This is the line of code I need to change:
which(!is.na(match(tbl$col1,arr)))
I am a newbie to python, would really appreciate the help
There is a simpler way to achieve the same objective in R:
which(tbl$col1 %in% arr)
which can be translated to Python (I'm considering that tbl is a Pandas dataframe here):
import numpy as np
np.where(tbl[col1].isin(arr))[0]
You should remember that Python is 0-indexed, though.
Any way to do the from - import from Python in Reticulate without having to import the whole module?
example: from tensorflow import keras
I know about the solution below, but it imports the whole module anyway...
keras <- import('tensorflow')$keras
I am not sure, but if you are writing your r code in an rmd file, wouldn't you be able to do it directly in a python chunk like this:
python
from ... import ...
My colleague gave me a big R function and I have to use it in the pipeline which will be developed in python3. In theory I have two options:
convert R into python
directly use R function in python script (for example by importing like a module)
What do you suggest? and how can I do each of these options?
Using rpy2.robjects might help ('function.R' is the r code)
import rpy2.robjects as robjects
robjects.r.source("function.R")
result refers to the output of the function
print(robjects.globalenv["result"])
I use iPython Notebook for scientific applications and I'm always plotting experimental data sets. The default image rendering and color cycling behavior of the combination of iPython Notebook and Matplotlib is pretty bad, but it's great after the following tweaks.
# ipython notebook specific
%pylab inline
# imports
from matplotlib import pyplot as plt
import matplotlib as mpl
from seaborn.apionly import set_palette
from IPython.display import set_matplotlib_formats
# configure plotting
set_matplotlib_formats('pdf', 'svg')
set_palette('Set1', n_colors=15, desat=None)
mpl.rcParams['figure.figsize']=(12.0,2.0)
I don't want to have to enter these manually in every notebook. How can I have these executed for all notebooks I'll ever create?
You can create Python files in $HOME/.ipython/profile_default/startup/ that contains the code you want executed at startup.
For example, you can create $HOME/.ipython/profile_default/startup/00-init.py:
# imports
from matplotlib import pyplot as plt
import matplotlib as mpl
from seaborn.apionly import set_palette
from IPython.display import set_matplotlib_formats
# configure plotting
set_matplotlib_formats('pdf', 'svg')
set_palette('Set1', n_colors=15, desat=None)
mpl.rcParams['figure.figsize']=(12.0,2.0)
Note that IPython magics are not supported here, so %matplotlib inline won't work. This question deals with making %matplotlib inline the default.
You should be aware that if you change the defaults for your IPython environment, your notebooks may not work on other people's IPython installations.
I want to use output from python program and barplot it using R.
I tried using rPy2
import rpy2.robjects as robjects
A= 2
B=4
plot = robjects.IntVector([A,D])
now to call barplot(plot) function. Please guide, even help using any other python package is appreciated