Questions tagged «kaggle»

3
对象是可枚举但不可索引的吗?
问题摘要和问题 我正在尝试查看对象内的一些数据,这些数据可以枚举但不能建立索引。我仍然对python不熟悉,但是我不知道这是怎么可能的。 如果可以枚举,为什么不能通过枚举相同的方式访问索引?如果没有,是否可以单独访问这些项目? 实际例子 import tensorflow_datasets as tfds train_validation_split = tfds.Split.TRAIN.subsplit([6, 4]) (train_data, validation_data), test_data = tfds.load( name="imdb_reviews", split=(train_validation_split, tfds.Split.TEST), as_supervised=True) 选取数据集的选择子集 foo = train_data.take(5) 我可以foo用枚举进行迭代: [In] for i, x in enumerate(foo): print(i) 产生预期的输出: 0 1 2 3 4 但是,当我尝试对其进行索引时,出现foo[0]此错误: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-44-2acbea6d9862> in <module> …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.