在本文中,我们将给您介绍关于Python错误:IndexError:只有整数,切片`:`,省略号`...`,numpy.newaxis`None`和整数或布尔数组都是有效的索引的详细内容,此外,我们还
在本文中,我们将给您介绍关于Python错误:IndexError:只有整数,切片`:`,省略号`...`,numpy.newaxis`None`和整数或布尔数组都是有效的索引的详细内容,此外,我们还将为您提供关于'(slice(None, None, None), 0)' 是绘制决策函数的无效键、.pip的时候出现Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))…………、IndexError:只有整数、切片 (`:`)、省略号 (`...`)、numpy.newaxis (`None`) 和整数或布尔数组是有效的索引,我该如何解决?、IndexError:只有整数、切片`:`、省略号`...`、numpy.newaxis`None`和整数或布尔数组是有效的索引错误的知识。
本文目录一览:- Python错误:IndexError:只有整数,切片`:`,省略号`...`,numpy.newaxis`None`和整数或布尔数组都是有效的索引
- '(slice(None, None, None), 0)' 是绘制决策函数的无效键
- .pip的时候出现Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))…………
- IndexError:只有整数、切片 (`:`)、省略号 (`...`)、numpy.newaxis (`None`) 和整数或布尔数组是有效的索引,我该如何解决?
- IndexError:只有整数、切片`:`、省略号`...`、numpy.newaxis`None`和整数或布尔数组是有效的索引错误
Python错误:IndexError:只有整数,切片`:`,省略号`...`,numpy.newaxis`None`和整数或布尔数组都是有效的索引
如何解决Python错误:IndexError:只有整数,切片`:`,省略号`...`,numpy.newaxis`None`和整数或布尔数组都是有效的索引
错误-
Python错误:IndexError:仅整数,切片(
:
),省略号 ({...
),numpy.newaxis(None
)和整数或布尔数组为 有效索引
注意- 我怀疑np.polyval有问题。
代码-
x = list(range(348))
x_data = np.array(x)
y_data = np.array(new_forces)
p = np.polyfit(x_data,y_data,15)
yp = np.polyval(p,x_data)
fig = plt.figure()
fig,ax = plt.subplots()
ax.plot(yp,color=''green'',linestyle=''solid'')
ax.legend()
fig.savefig("graphsW2/"+str(hgain)+"-"+str(gain)+"-"+str(gaincalc)+"-"+"WForcescumul+P&L-"+p["symbol"]+ylindex+".png")
'(slice(None, None, None), 0)' 是绘制决策函数的无效键
如何解决''(slice(None, None, None), 0)'' 是绘制决策函数的无效键
# Plot the training points
ax.scatter(Xtrain.iloc[:,0].values,Xtrain.iloc[:,1].values,c=Ytrain,cmap=cm_bright,edgecolors=''k'')
我正在尝试运行此代码,但一直收到 (slice(None,None,None),0) is an invalid key
错误。关于我做错了什么以及如何解决它的任何想法?
.pip的时候出现Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))…………
pip的幺蛾子:
有时候在用pip安装python中的包的时候,会出先请求失败的现象,一开始还以为是自己的网不够好,后来才发现。。。。。。
原因:
pip的下载源存在国外和国内之分,一般来说国内的源下载会块很多,国外的源会有速度限制,从而造成请求失败从而不能安装你想要的模块.
解决方法:
几种国内常用的pip源
阿里云 :http://mirrors.aliyun.com/pypi/simple/
中国科技大学 :https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) :http://pypi.douban.com/simple/
清华大学: https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 :http://pypi.mirrors.ustc.edu.cn/simple/
写入文件内容:
1 [global]
2 index-url = https://pypi.tuna.tsinghua.edu.cn/simple
3 [install]
4 trusted-host=mirrors.aliyun.com
在windoms中:
直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini
在linu中
Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
在文件上写入上面配置文件中的内容
在运用pip安装模会发现速度快了很多。
IndexError:只有整数、切片 (`:`)、省略号 (`...`)、numpy.newaxis (`None`) 和整数或布尔数组是有效的索引,我该如何解决?
如何解决IndexError:只有整数、切片 (`:`)、省略号 (`...`)、numpy.newaxis (`None`) 和整数或布尔数组是有效的索引,我该如何解决?
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt2
import matplotlib.cm as cm
import numpy as np # linear algebra
import pandas as pd
kanser = pd.read_csv(''breast-cancer-wisconsin.csv'') #veri seti okuma
kanser.dropna(inplace=True) #kayıp değerlerin olduğu yerleri kaldırma
kanser.Class = [1 if i == "benign" else 0 for i in kanser.Class] #target için tür döüşümü yapma
X=kanser.drop(''Class'',axis = 1)
y=kanser.Class.values
from sklearn.manifold import TSNE
tsne = TSNE(verbose=1,perplexity=40,n_iter= 4000)
Y = tsne.fit_transform(X)
from sklearn.cluster import KMeans
kmns = KMeans(n_clusters=2,init=''k-means++'',n_init=10,max_iter=300,tol=0.0001,precompute_distances=''auto'',verbose=0,random_state=None,copy_x=True,n_jobs=1,algorithm=''auto'')
kY = kmns.fit_predict(X)
f,(ax1,ax2) = plt.subplots(1,2,sharey=True)
ax1.scatter(Y[:,0],Y[:,1],c=kY,cmap = "jet",edgecolor = "None",alpha=0.35)
ax1.set_title(''k-means clustering plot'')
ax2.scatter(Y[:,c = y[''Class''],alpha=0.35)
ax2.set_title(''Actual clusters'')
我收到此错误。
IndexError Traceback (most recent call last)
<ipython-input-3-fd6a6e8ca8a9> in <module>()
26 ax1.set_title(''k-means clustering plot'')
27
---> 28 ax2.scatter(Y[:,alpha=0.35)
29 ax2.set_title(''Actual clusters'')
IndexError: only integers,slices (`:`),ellipsis (`...`),numpy.newaxis (`None`) and integer or boolean arrays are valid indices
我能为此做什么?
解决方法
我运行了您的代码并查看了变量。您的对象“y”似乎是一个列表,其 _getitem_ 方法不接受字符串。
from sklearn import datasets
data = datasets.load_breast_cancer()
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt2
import matplotlib.cm as cm
import numpy as np # linear algebra
import pandas as pd
# kanser = pd.read_csv(''breast-cancer-wisconsin.csv'') #veri seti okuma
kanser = pd.DataFrame(data.data,columns = data.feature_names)
kanser[''Class''] = data.target_names[data.target]
kanser.dropna(inplace=True) #kayıp değerlerin olduğu yerleri kaldırma
kanser.Class = [1 if i == "benign" else 0 for i in kanser.Class] #target için tür döüşümü yapma
X=kanser.drop(''Class'',axis = 1)
y=kanser.Class.values
from sklearn.manifold import TSNE
tsne = TSNE(verbose=1,perplexity=40,n_iter= 4000)
Y = tsne.fit_transform(X)
from sklearn.cluster import KMeans
kmns = KMeans(n_clusters=2,init=''k-means++'',n_init=10,max_iter=300,tol=0.0001,precompute_distances=''auto'',verbose=0,random_state=None,copy_x=True,n_jobs=1,algorithm=''auto'')
kY = kmns.fit_predict(X)
f,(ax1,ax2) = plt.subplots(1,2,sharey=True)
ax1.scatter(Y[:,0],Y[:,1],c=kY,cmap = "jet",edgecolor = "None",alpha=0.35)
ax1.set_title(''k-means clustering plot'')
xs = Y[:,0]
ys = Y[:,1]
print(f''y = {y}'')
cs = y[''Class'']
ax2.scatter(xs,ys,c = cs,alpha=0.35)
ax2.set_title(''Actual clusters'')
输出:
[t-SNE] Computing 121 nearest neighbors...
[t-SNE] Indexed 569 samples in 0.001s...
[t-SNE] Computed neighbors for 569 samples in 0.018s...
[t-SNE] Computed conditional probabilities for sample 569 / 569
[t-SNE] Mean sigma: 33.679708
[t-SNE] KL divergence after 250 iterations with early exaggeration: 50.078777
[t-SNE] KL divergence after 4000 iterations: 0.221172
y = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 1 0 0
1 0 1 0 0 1 1 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 1 0 1 1
1 1 1 1 1 1 0 0 0 1 0 0 1 1 1 0 0 1 0 1 0 0 1 0 0 1 1 0 1 1 0 1 1 1 1 0 1
1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 1 1 0 0 0 1 0
1 0 1 1 1 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 1 1 0 1 0 0 0 0 1 1 0 0 1 1
1 0 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 1 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 0 1 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1
1 0 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 1 1
1 1 0 1 0 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0
0 1 0 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1
1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 0 1 1 1 1 1 0 1 1
0 1 0 1 1 0 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1 0 1 0 1 1 1 1 1 0 1 1 0 1 0 1 0 0
1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 0 0 0 0 0 0 1]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-5-73736c0bb107> in <module>()
37 print(f''y = {y}'')
38
---> 39 cs = y[''Class'']
40
41
IndexError: only integers,slices (`:`),ellipsis (`...`),numpy.newaxis (`None`) and integer or boolean arrays are valid indices
IndexError:只有整数、切片`:`、省略号`...`、numpy.newaxis`None`和整数或布尔数组是有效的索引错误
如何解决IndexError:只有整数、切片`:`、省略号`...`、numpy.newaxis`None`和整数或布尔数组是有效的索引错误
嗨,我有一个坐标列表来选择图像中的某些感兴趣区域。但是当我将这些坐标传递给图像时,我收到了标题中的错误
代码如下:
coord_list =[''[55:130,190:707]'',''[178:280,30:387]'',''[181:273,424:739]'',424:739]'']
image1 = cv2.imread(r''C:\\\\Users\\\\User\\\\Desktop\\\\images\\\\Sample.jpg'')
image1 = cv2.resize(image,(1000,1000))
image_roi = image1[coord_list[0]]
cv2.imshow(''img'',image_roi)
cv2.waitKey(0)
它必须从列表中迭代,因为我必须对文件夹中的许多图像使用相同的坐标
解决方法
您不能直接对索引为字符串的数组进行切片。你必须先评估它:
image_roi = eval(''image1''+coord_list[0])
编辑:
为了回应您的评论,您可以使用 numpy
来表示。 这样就可以直接使用了,不需要使用eval()
import cv2
import numpy as np
coord_list = [np.s_[55:130,190:707],np.s_[178:280,30:387],np.s_[181:273,424:739],np.s_[182:273,424:738] ]
image1 = cv2.imread(''dog.jpg'')
image1 = cv2.resize(image1,(1000,1000))
image_roi = image1[coord_list[0]]
cv2.imshow(''img'',image_roi)
cv2.waitKey(0)
今天的关于Python错误:IndexError:只有整数,切片`:`,省略号`...`,numpy.newaxis`None`和整数或布尔数组都是有效的索引的分享已经结束,谢谢您的关注,如果想了解更多关于'(slice(None, None, None), 0)' 是绘制决策函数的无效键、.pip的时候出现Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))…………、IndexError:只有整数、切片 (`:`)、省略号 (`...`)、numpy.newaxis (`None`) 和整数或布尔数组是有效的索引,我该如何解决?、IndexError:只有整数、切片`:`、省略号`...`、numpy.newaxis`None`和整数或布尔数组是有效的索引错误的相关知识,请在本站进行查询。
本文标签: