此Python代码中的[:5]
和[5]
有什么区别?
y_test_predicted = model.predict(X_test)
residuals = Y_test - y_test_predicted
print(residuals[:5])
print(residuals[5])
答案 0 :(得分:0)
您可以在此link中找到有关切片的有用信息。
请参考以下简单示例以了解它:
list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'j']
print(list[5]) #it will print: f
print(list[:5]) #it will print: ['a', 'b', 'c', 'd', 'e'], indices form 0 to 4
#List Slicing: list[start:stop:step]