'float' object has no attribute 'exp' in spyder python - python-3.x

import numpy as np
from scipy import interpolate
import pylab as py
import pandas as pd
def func(x1):
return x*np.exp(-5.0*x1**2)
dataset=pd.read_excel('Messwerte_FIBRE1.xlsx')
dataset=dataset.drop([0])
index=[1]
index2=[9]
x=dataset.iloc[:, index]
y=dataset.iloc[:, index2]
x1=np.array(x)
y1=np.array(y)
fvals=func(x1)
File "C:/Users/Windows 10/.spyder-py3/RBF.py", line 10, in func
return x*np.exp(-5.0*x1**2)
AttributeError: 'float' object has no attribute 'exp'
Any1 can help me to solve this problem?
Here is the png of my textfile

np.exp(...)
'float' object has no attribute 'exp'
This means that you likely have redefined the name np, and now it's a floating-point number and not the numpy module any more.
Look around your code for np = ....

Related

Sklearn with Joblib raises "AttributeError: 'NoneType' object has no attribute 'submit'"

I get the weirdest error when I use joblib (1.2.0) wit scikit-learn. Here is a MWE:
import numpy as np
from joblib import Parallel, delayed, parallel_backend
from sklearn.neighbors import NearestNeighbors
def it():
df = np.random.randn(1000).reshape(-1,1)
NearestNeighbors(n_neighbors=2, p=2).fit(df).kneighbors(df)
yield 1
f = lambda x: 1
with parallel_backend("loky", inner_max_num_threads=1):
res = Parallel(n_jobs=2)(delayed(f)(p) for p in it())
Running this code, I get AttributeError: 'NoneType' object has no attribute 'submit'. I cannot get around it. If I comment out the call to NearestNeighbors the problem disappears. If I let n_jobs=1 the problem disappears. If I skip the context manager - the problem disappears.

Invalid file path or buffer object type

When running the below code I am getting the following error:
Invalid file path or buffer object type: <class 'pandas.core.frame.DataFrame'>
Code:
from pandas import read_csv
import pandas as pd
import numpy as np
from seaborn import lineplot
from matplotlib import pyplot
df = pd.read_csv("Sexo-Resultado.csv")
dataset = read_csv(df, header=0)
lineplot(x='Sexo', y='Resultado', data=dataset)
pyplot.show()
I believe the error is on the df?? the data only has two columns, Sexo and Resultado

AttributeError: module 'matplotlib' has no attribute 'scatter'

I'm trying to make cluster of latitude and longitude.
the code gave an error in plt.scatter(data['Lng'],data['Lat']) line
the error is:
AttributeError: module 'matplotlib' has no attribute 'scatter'
code:
import numpy as np
import pandas as pd
import matplotlib as plt
import seaborn as sns
sns.set()
from sklearn.cluster import KMeans
data = pd.read_csv("pk.csv")
data.head()
lat_long = data.drop(['country', 'iso2','admin', 'capital','population',
'population_proper'] , axis = 1)
lat_long.head()
plt.scatter(data['Lng'],data['Lat']) # error here
It should be:
import matplotlib.pyplot as plt
Or it can be:
from matplotlib import pyplot as plt
Also you can read PEP 328 for more information and clearity.

AttributeError: 'SerialBus' object has no attribute 'can'

I am writing a python code to receive the can data via a USB2CAN device. I receive the following error:
AttributeError: 'SerialBus' object has no attribute 'can'
from can.interfaces import serial
import random
import time
import datetime
import matplotlib.pyplot as plt
ser= can.interfaces.serial.serial_can.SerialBus('COM5',115200,timeout=None,rtscts=0)
for i in range(100) :
s= ser.can.interfaces.serial.SerialBus._recv_internal(timeout=None)
print(s)

Error:'NoneType' object has no attribute '_inbound_nodes'

I've been trying to encode a model that uses a squeeze-exctitation block.
I'm cluless about the error. Please suggest alternatives.
import keras
from keras.models import Sequential,Model
from keras.layers import,Input,Dense,Conv2D,MaxPooling2D,Flatten,GlobalAveragePooling2D,BatchNormalization,Lambda,Conv2DTranspose,Reshape,Add,Multiply
import numpy as np
import io
x_inp=Input(shape=(6,8,128))
print(np.shape(x_inp))
def SEblock(x,cn):
sh_x=x
x=GlobalAveragePooling2D()(x)
x=Dense(cn//16,activation='relu')(x)
x=Dense(cn,activation='sigmoid')(x)
x=Reshape((1,1,cn))(x)
x=sh_x*x
y=GlobalAveragePooling2D()(x)
return y
y=SEblock(x_inp,128)
model=Model(inputs=x_inp,outputs=y)
Error message when the above code was run:
node = layer._inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
Replace
x=sh_x*x
with
x = Multiply()([sh_x, x])

Resources