||
a=[1,2,3,4]
b=np.array([1,2,3])
以b 为索引,获取a中的值,按照常规的写法 a[b] 则会报错
TypeError: only integer scalar arrays can be converted to a scalar index
意思是索引(即numpy数组)的格式并不是 整型标量数组,正确的写法如下:、
np.array(a)[b]
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-19 16:27
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社