I run visual studio code on Windows 10. Current version of my visual studio code is 1.45.1. I am running a Python (version 3.7.4 64-bit) on it. My visual studio code takes 5 to 10 minutes to load following libraries:
import pandas as pd
import numpy as np
from datetime import datetime, date
from scipy.stats import ttest_ind
from scipy.stats import ttest_ind_from_stats
from scipy.stats import ttest_1samp
import seaborn as sns
import matplotlib.pyplot as plt
I tried to find a solution online to speed up, but couldn't find it. Is anyone experience the same issue? How could we speed up the visual code?
from time import perf_counter
a=perf_counter()
import pandas as pd
b=perf_counter()
import numpy as np
c=perf_counter()
from datetime import datetime, date
d=perf_counter()
from scipy.stats import ttest_ind
e=perf_counter()
from scipy.stats import ttest_ind_from_stats
f=perf_counter()
from scipy.stats import ttest_1samp
g=perf_counter()
import seaborn as sns
h=perf_counter()
import matplotlib.pyplot as plt
i=perf_counter()
print(b-a)
print(c-b)
print(d-c)
print(e-d)
print(f-e)
print(g-f)
print(h-g)
print(i-h)
Take this to analyze which imports take too much time.
Then take 'cProfile' to do exactly analysis. you can refer to this page.
Related
from sklearn.decomposition import PCA as sklearnPCA
pca = PCA(n_components=2)
pca_representation = pca.fit_transform(dataset_norm[index])
import numpy as np
from sklearn.datasets import make_s_curve
import matplotlib.pyplot as plt
from sklearn.manifold import Isomap as sklearnisomap
from mpl_toolkits.mplot3d import Axes3D
iso = Isomap(n_components=2, n_neighbors=40)
iso_representation = iso.fit_transform(dataset_norm[index])
I use google colab.
When I run the code:
iso_representation = iso.fit_transform(dataset_norm[index]),
It doesn't work, the system message says: Your session crashed after using all available RAM.
But the PCA module is working correctly, I have looked up many answers but can't solve this problem, and other codes are not working correctly, am I overlooking something?
I am running a very simple Python script:
from tftb.generators import amgauss, fmlin
I get this error:
C:\Users\Anaconda3\envs\tf_gpu\lib\site-packages\tftb-0.0.1-py3.6.egg\tftb\processing\affine.py in <module>
12
13 import numpy as np
---> 14 from matplotlib.mlab import find
15 from scipy.signal import hilbert
16 from scipy.optimize import brenth, newton
ImportError: cannot import name 'find'
I believe find is no longer in versions >=3. How can I get around this without downgrading Matplotlib?
The code of the matplotlib.mlab.find function was literally
import numpy as np
def find(condition):
res, = np.nonzero(np.ravel(condition))
return res
You may replace any occurance with that function.
I need to include Python code chunks in an R Markdown HTML. However, when I do so, the plot doesn't show up.
This is the code chunk I have which want to implement. I know this works in Python.
```{python, results='asis'}
import numpy as np
import matplotlib.pyplot as plt
import numpy.random as rng
import matplotlib.cm as cm
from matplotlib.animation import FuncAnimation
radii=(rng.random(int(1e3))+1)**2
iota=2*np.pi*rng.random(int(1e3))
x_posit=np.sqrt(radii)*np.cos(iota)
y_posit=np.sqrt(radii)*np.sin(iota)
plt.plot(x_posit, y_posit, 'go')
```
I expect to get a plot like this
But instead I get this, that is no graph in the R markdown Document. I'm knitting to HTML
Install the library reticulate via install.packages("reticulate") and load this chunk before your code presented above:
```{r setup, include=FALSE}
library(knitr)
library(reticulate)
knitr::knit_engines$set(python = reticulate::eng_python)
```
```{python}
import numpy as np
import matplotlib.pyplot as plt
import numpy.random as rng
import matplotlib.cm as cm
from matplotlib.animation import FuncAnimation
radii=(rng.random(int(1e3))+1)**2
iota=2*np.pi*rng.random(int(1e3))
x_posit=np.sqrt(radii)*np.cos(iota)
y_posit=np.sqrt(radii)*np.sin(iota)
plt.plot(x_posit, y_posit, 'go')
plt.show()
```
Note the plt.show() command.
This will produce your expected output!
Exactly how J_F above described. Just as a reminder: In case you have more than one Python version on your system e.g. Mac with Python 2.7 and 3.x.
```{r setup, include=FALSE}
Library(knitr)
Library(reticulate)
knitr::knit_engines$set(python3 = reticulate::eng_python)
```
```{python3}
enter code here
```
I'm trying to import a series of modules into my Python 3.5 code. I use the following code to import:
# import packages for analysis and modeling
import pandas as pd # data frame operations; use pandas 0.18
from pandas.tools.rplot import RPlot, TrellisGrid, GeomPoint, \
ScaleRandomColour # trellis/lattice plotting
import numpy as np # arrays and math functions
from scipy.stats import uniform # for training-and-test split
import statsmodels.api as sm # statistical models (including regression)
import statsmodels.formula.api as smf # R-like model specification
import matplotlib.pyplot as plt # 2D plotting
When i use this code, I receive the following error:
ImportError Traceback (most recent call last)
/var/folders/zy/snhf2bh51v33ny6nf7fyr4wh0000gn/T/tmpdxMQ0Y.py in <module>()
7 # import packages for analysis and modeling
8 import pandas as pd # data frame operations; use pandas 0.18
----> 9 from pandas.tools.rplot import RPlot, TrellisGrid, GeomPoint, \
10 ScaleRandomColour # trellis/lattice plotting
11 import numpy as np # arrays and math functions
ImportError: No module named 'pandas.tools.rplot'
I tried this code with "pd" and with "pandas" written out. I confirmed that pandas was installed by manually typing in import pandas as pd and then confirming its existence by typing in "pd" and receiving the following message: <module 'pandas' from '/Users/me/Library/Enthought/Canopy/edm/envs/User/lib/python3.5/site-packages/pandas/__init__.py'>
What is causing this to happen?
Renaming it during import with as doesn't mean Python will be able to find the original module (pandas) when you use the name pd at a later import statement. Python will look for a module named pd which it will not find.
Since pd does not correspond to some module while pandas does, you'll need to use from pandas import tools in order to get it to work.
The following block of code
%matplotlib inline
import sys
import pandas as pd
sys.path.append("C:\Users\%USER%\PycharmProjects\cap_rate")
import mongo
import c_lib
import t_lib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
Is taking upwards of ten minutes to run.
Does anyone have an idea as to what may be the root cause of this?
No major warnings/output on my end outside of severe slowness.
I rebooted and it is much faster.