GVKun编程网logo

AttributeError:“ PerReplica”对象没有属性“ numpy”(此对象没有属性)

4

在本文中,您将会了解到关于AttributeError:“PerReplica”对象没有属性“numpy”的新资讯,同时我们还将为您解释此对象没有属性的相关在本文中,我们将带你探索AttributeE

在本文中,您将会了解到关于AttributeError:“ PerReplica”对象没有属性“ numpy”的新资讯,同时我们还将为您解释此对象没有属性的相关在本文中,我们将带你探索AttributeError:“ PerReplica”对象没有属性“ numpy”的奥秘,分析此对象没有属性的特点,并给出一些关于AttributeError-'numpy.ndarray'对象没有属性'drop'、AttributeError: 'numpy.float64' 对象没有属性 '_id'、AttributeError: 'numpy.ndarray' 对象没有属性 'cost_'、AttributeError: 'numpy.ndarray' 对象没有属性 'fromarray'的实用技巧。

本文目录一览:

AttributeError:“ PerReplica”对象没有属性“ numpy”(此对象没有属性)

AttributeError:“ PerReplica”对象没有属性“ numpy”(此对象没有属性)

我目前正在使用相同的仓库,并遇到此错误。不幸的是我还没有修复,但是与此同时我正在使用变通方法。培训尝试评估网络时,将引发此错误。它每隔x次迭代执行一次此操作,具体取决于您在文件“ ./examples/fastspeech2/conf/fastspeech2.v1.yaml”中将eval_internal_steps设置为什么。如果将此数字增加到大于train_max_steps,则永远不会调用引发错误的函数。

引发此错误的函数是generate_and_save_intermediate_result(batch),据我所知,您可以在没有该函数的情况下进行训练。

AttributeError-'numpy.ndarray'对象没有属性'drop'

AttributeError-'numpy.ndarray'对象没有属性'drop'

如何解决AttributeError-''numpy.ndarray''对象没有属性''drop''?

对于当前的项目,我计划在包含数字数据的CSV集合上运行scikit-learn随机梯度助推器算法。

调用脚本的X = Germany.drop(''Status'',axis=''columns'')时,我收到了AttributeError: ''numpy.ndarray'' object has no attribute ''drop''

我认为此错误可能与以下事实有关:我正在转换CSV数据pd.to_numeric,这也可能会转换字符串标题。有没有可以进行此操作的智能调整?

CSV数据具有以下结构:

enter image description here

相应的代码如下:

Germany = pd.read_csv(''./Germany_filtered.csv'',index_col=0)
Germany = Germany.fillna("")
Germany = pd.to_numeric(Germany.columns.str,errors=''coerce'')
Germany.head()

X = Germany.drop(''Status'',axis=''columns'')
y = Germany[''Status'']

解决方法

In [167]: df = pd.DataFrame(np.arange(12).reshape(3,4),columns=[''a'',''b'',''c'',''d''])

drop在数据框上可以正常工作:

In [168]: df.drop(''c'',axis=''columns'')
Out[168]: 
   a  b   d
0  0  1   3
1  4  5   7
2  8  9  11

to_numeric产生一个numpy数组:

In [169]: x = pd.to_numeric(df.columns.str,errors=''coerce'')
In [170]: x
Out[170]: 
array(<pandas.core.strings.StringMethods object at 0x7fef602862b0>,dtype=object)
In [171]: type(x)
Out[171]: numpy.ndarray

在进入head之前,它应该抱怨drop

In [172]: x.head()
Traceback (most recent call last):
  File "<ipython-input-172-830ed5e65d76>",line 1,in <module>
    x.head()
AttributeError: ''numpy.ndarray'' object has no attribute ''head''

In [173]: x.drop()
Traceback (most recent call last):
  File "<ipython-input-173-6d3a33341569>",in <module>
    x.drop()
AttributeError: ''numpy.ndarray'' object has no attribute ''drop''

to_numeric文档怎么说?我没有与之合作,但显然您不想将其传递给df.columns.str对象。我尚未使用此功能,但让我们尝试将其传递给数据框:

In [176]: x = pd.to_numeric(df,errors=''coerce'')
Traceback (most recent call last):
  File "<ipython-input-176-d095b0166b8f>",in <module>
    x = pd.to_numeric(df,errors=''coerce'')
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/tools/numeric.py",line 139,in to_numeric
    raise TypeError("arg must be a list,tuple,1-d array,or Series")
TypeError: arg must be a list,or Series

因此,让我们传递一列/系列:

In [177]: x = pd.to_numeric(df[''a''],errors=''coerce'')
In [178]: x
Out[178]: 
0    0
1    4
2    8
Name: a,dtype: int64

结果Series可以在同一列或新列中分配回数据框:

In [179]: df[''a''] = x
In [180]: df
Out[180]: 
   a  b   c   d
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11

现在在我的示例框架中,无需进行此转换,但它应该可以为您提供一些帮助。


让我们尝试真正的字符串转换:

In [195]: df[''a''] = [''00'',''04'',''LS'']
In [196]: df
Out[196]: 
    a  b   c   d
0  00  1   2   3
1  04  5   6   7
2  LS  9  10  11

链接的答案无济于事:

In [197]: pd.to_numeric(df.columns.str,errors=''coerce'')
Out[197]: 
array(<pandas.core.strings.StringMethods object at 0x7fef602862b0>,dtype=object)

但是我的版本确实产生了一个数字系列:

In [198]: pd.to_numeric(df[''a''],errors=''coerce'')
Out[198]: 
0    0.0
1    4.0
2    NaN
Name: a,dtype: float64

AttributeError: 'numpy.float64' 对象没有属性 '_id'

AttributeError: 'numpy.float64' 对象没有属性 '_id'

如何解决AttributeError: ''numpy.float64'' 对象没有属性 ''_id''?

我正在为我的训练回合进行自定义,但是在计算 loss_value 时出现此错误。我该怎么做才能修复它?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

AttributeError: 'numpy.ndarray' 对象没有属性 'cost_'

AttributeError: 'numpy.ndarray' 对象没有属性 'cost_'

如何解决AttributeError: ''numpy.ndarray'' 对象没有属性 ''cost_''

我正在尝试进行 Kprototype 聚类算法。当我运行模型并尝试按如下方式绘制成本图时,我总是收到 label_ 和 cost_ 函数的“无属性”错误。我检查了几个网站上的示例,但没有区别。我能做什么?感谢您的帮助。

1)

  1. from kmodes.kmodes import KModes
  2. from kmodes.kprototypes import KPrototypes
  3. kproto1 = KPrototypes(n_clusters=15,init=''Cao'').fit_predict(data,categorical = [23])
  4. labels= kproto1.labels_
  5. **AttributeError: ''numpy.ndarray'' object has no attribute ''label_''**
  1. cost = []
  2. range_cluster=[5,8,10,15,20,25,30,35,40,45,50,55,70,85,100]
  3. for num_clusters in range_cluster:
  4. kproto = KPrototypes(n_clusters=num_clusters,categorical=[23])
  5. cost.append(kproto.cost_)
  6. plt.plot(cost)

解决方法

根据source code,有两种方法可以实现:
fit_predict 方法将返回一个标签元组,成本。因此,要获取标签,您应该:

  1. kproto1_result = KPrototypes(n_clusters=15,init=''Cao'').fit_predict(data,categorical = [23])
  2. labels= kproto1[0]

或者第二种方法只是使用 fit 方法:

  1. kproto1 = KPrototypes(n_clusters=15,init=''Cao'').fit(data,categorical = [23])
  2. labels = kproto1.labels_

AttributeError: 'numpy.ndarray' 对象没有属性 'fromarray'

AttributeError: 'numpy.ndarray' 对象没有属性 'fromarray'

如何解决AttributeError: ''numpy.ndarray'' 对象没有属性 ''fromarray''

我有一个形状为 (256,256)

的图像数组
  1. array([[ 1.83929426,2.27074315,2.5218986,...,5.58716559,7.68013398,8.48954239],[ 7.7554863,1.80131326,4.08562626,11.43703752,10.6897957,2.21642752],[ 3.5976206,17.32215998,3.94093576,2.92133073,5.27458118,6.51157218],[12.61920987,5.42883218,4.91278887,11.86499776,1.95860585,1.96206125],[ 4.18047027,2.85057039,11.86617946,3.56434097,8.87239311,2.14273459],[ 5.36091217,9.16876533,2.52525961,8.17177924,3.85081341,6.46705723]])

当我尝试使用 Image.fromarray() 加载时出现错误 AttributeError: ''numpy.ndarray'' object has no attribute ''fromarray''

代码:

  1. import numpy as np
  2. from scipy.io import loadmat
  3. import matplotlib.pyplot as plt
  4. matcontent = loadmat(''/content/PIfile_new.mat'',appendmat=True)
  5. matcontent.keys()
  6. highest = np.max(matcontent[''I32''])
  7. lowest = np.min(matcontent[''I32''])
  8. print(highest,lowest)
  9. Image = np.divide(matcontent[''I32''],highest )
  10. highest = np.max(Image)
  11. lowest = np.min(Image)
  12. print(highest,lowest)
  13. Image_255 = Image*255

输出: 283.52991767049167 0.09813473030519577 1.0 0.000346117725817014

  1. Image.fromarray(Image_255)

错误:

  1. AttributeError Traceback (most recent call last)
  2. <ipython-input-28-698d66d71bc6> in <module>()
  3. ----> 1 Image.fromarray(Image_255)
  4. AttributeError: ''numpy.ndarray'' object has no attribute ''fromarray''

关于AttributeError:“ PerReplica”对象没有属性“ numpy”此对象没有属性的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于AttributeError-'numpy.ndarray'对象没有属性'drop'、AttributeError: 'numpy.float64' 对象没有属性 '_id'、AttributeError: 'numpy.ndarray' 对象没有属性 'cost_'、AttributeError: 'numpy.ndarray' 对象没有属性 'fromarray'等相关内容,可以在本站寻找。

本文标签: