I want to write a program which performs a periodogram on a series of measurement values listed in the file 'flux.txt' but I get the error:
module 'numpy' has no attribute 'testing'
The error also appears if I comment the whole code. I tried to update numpy but it's still updated. May someone help me please?
from scipy import signal
import numpy as np
import matplotlib.pyplot as plt
with open('flux.txt','r') as f:
item = f.readlines
print(item)
signal.periodogram(item)
plt.show()
Related
I am trying to import scipy.interpolate using the following code:
from scipy.interpolate import interp1d
but I get the following error:
AttributeError: scipy.spatial.qhull is deprecated and has no attribute __pyx_capi__. Try looking in scipy.spatial instead.
How should I fix this?
I am trying to run some code on a spark kubernetes cluster
"spark.kubernetes.container.image", "kublr/spark-py:2.4.0-hadoop-2.6"
The code I am trying to run is the following
def getMax(row, subtract):
'''
getMax takes two parameters -
row: array with parameters
subtract: normal value of the parameter
It outputs the value most distant from the normal
'''
try:
row = np.array(row)
out = row[np.argmax(row-subtract)]
except ValueError:
return None
return out.item()
from pyspark.sql.types import FloatType
udf_getMax = F.udf(getMax, FloatType())
The dataframe I am passing is as below
However I am getting the following error
ModuleNotFoundError: No module named 'numpy'
When I did a stackoverflow serach I could find similar issue of numpy import error in spark in yarn.
ImportError: No module named numpy on spark workers
And the crazy part is I am able to import numpy outside and
import numpy as np
command outside the function is not getting any errors.
Why is this happening? How to fix this or how to go forward. Any help is appreciated.
Thank you
I am getting the error message : 'numpy.int64' object is not callable when trying to print a numpy array. This has never happened before and the error randomly appeared and I have not been able to resolve it.
I have tried restarting my computer. Jupyter notebook printed the array once, then when I ran the code again, the error reappeared.
My code:
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
myArray=np.linspace(0,4,4)
print(myArray)
Im trying to use the following code (example):
import pandas as pd
(import statsmodels.api as sm) - Tried adding, no luck
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
x = pd.DataFrame(imports a vector)
plot_acf(x)
There is some code in between, but the problem arises when Python tries to plot the autocorrelation using statsmodels, and returns the following error:
File "/Users/user/anaconda/lib/python3.6/site-packages/statsmodels/iolib/foreign.py",
line 20, in <module>
import statsmodels.tools.data as data_util
AttributeError: module 'statsmodels' has no attribute 'tools'
I tried reinstalling multiple libraries, but nothing seems to get me past this error. Could this be a statsmodels-side bug?
I have a very simple code but at the end i found problem which I couldn't solve or find any solution.
I can't draw plot. All I get is error AttributeError: 'numpy.float64' object has no attribute 'plot'
import pylab as p
import numpy as np
import sympy as s
import matplotlib
from random import random
X=np.arange(0,1000)
y=np.random.randint(100,size=1000)
if len(X)==len(y):
print "ok"
else:
print "not ok"
polyfit=np.polyfit(X,y,6)
poly1d=np.poly1d(polyfit)
print poly1d
i=1
my=[]
for i in X:
p=poly1d(i)
my.append(p)
print my
p.plot(X,my)
p.show()
I look after docs but I found nothing,google also can't help me.
You've overwritten the pylab module accidentally later on in your code by assigning something else to p. You can avoid this by just importing pylab and using, for example, pylab.plot.
You've also got some indentation issues, remember that indentation matters in Python.
Using matplotlib.pyplot is generally recommended as opposed to using pylab. As such I've modified the code below to use pyplot over pylab. I've also removed some unneeded parts of the code and generally tidied it up.
import matplotlib.pyplot as plt
import numpy as np
from random import random
X=np.arange(0,1000)
y=np.random.randint(100,size=1000)
if len(X)==len(y):
print("ok")
else:
print("not ok")
polyfit=np.polyfit(X,y,6)
poly1d=np.poly1d(polyfit)
my=[]
for i in X:
p=poly1d(i)
my.append(p)
plt.plot(X,my)
plt.show()