'numpy.int64' object is not callable when trying to print array - python

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)

Related

Trying to create a numpy array and failing

So I am trying to run a code that was regularly working, but now I get an error
The first lines of my code are:
import numpy as np
array = np.array([0,1,2])
Then, I get the following error:
'list' object is not callable
This code is working fine in Jupyter notebook. You might want to restart your session and try again. An other alternative would be to use a different name to assign the array object instead of 'array' itself.

Matplotlib backend shifts when using object detection API, QtAgg to Agg

The figure doesn't show up when using matplotlib with object detection API, But it works fine before I import some test method.
I'm using Anaconda virtual envionment, python 3.6 and the google object detection API.
import matplotlib.pyplot as plt
import tensorflow as tf
from matplotlib import patches
from object_detection.anchor_generators.multiple_grid_anchor_generator import create_ssd_anchors
from object_detection.models.ssd_mobilenet_v2_feature_extractor_test import SsdMobilenetV2FeatureExtractorTest
from object_detection.models.ssd_mobilenet_v2_feature_extractor_test import SsdMobilenetV2FeatureExtractorTest
The change happens when it comes to the last line
from object_detection.models.ssd_mobilenet_v2_feature_extractor_test import SsdMobilenetV2FeatureExtractorTest"
Before, I can show the figure, like plt.subplot(2,2), I get the figure pop up and the following:
(<Figure size 640x480 with 4 Axes>,
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f4615eb8ba8>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f4614d320f0>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x7f4614ce36a0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f4614c92c50>]],
dtype=object))
WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.
and "plt.get_backend()" shows "Qt5Agg".
but after the last line, the figure doesn't pop up, although I do get results from "plt.subplots(2,2)":
(<Figure size 640x480 with 4 Axes>,
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7f460b8a5f60>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f460b86b5c0>],
[<matplotlib.axes._subplots.AxesSubplot object at 0x7f460a7b2fd0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x7f460a7cb630>]],
dtype=object))
Now when I type "plt.get_backend()", it shows "Agg", not the previous "Qt5Agg". and "plt.show()" throws an error:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
#!/usr/bin/env python2
the interpreter I was using is
~/anaconda3/envs/py36/bin/python
Is there a shift of environment here?
The script for the last line can be found here
Thanks a lot for your time!
Solved. Have found this line in ~/models/research/object_detecion/utils/visualization_utils.py :
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
just comment it and works fine.
Solved. I am running locally on a virtual enironment and tried several suggested solution but with no success.
I tried what Yunfei Fang was suggesting above but then realized that by, commenting out the line of code import matplotlib; matplotlib.use('Agg') in the ~/models/research/object_detecion/utils/visualization_utils.py folder wasn't enough.
I found out by putting this code in the body of my script: print('matplotlib backend= ',matplotlib.get_backend()) as this was still returning "agg" so I had to add this matplotlib.use('MacOSX') at the end of the import section of the script.
I am running on a MacBook Pro with macOS Big Sur

Python 3 Attribute Error: Statsmodels has no attribute 'tools'

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?

module 'numpy' has no attribute 'testing'

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()

'numpy.float64' object has no attribute 'plot'

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()

Categories

Resources