[英]Converting numpy array to single integer
I am a new Python user, and am struggling with what is seemingly a very easy problem — yet I cannot seem to solve it. 我是Python的新用户,并且正在为看似非常简单的问题而苦苦挣扎-但我似乎无法解决它。 The problem is that I created an array from np that contains a single value.
问题是我从np创建了一个包含单个值的数组。
In: distance_index
Out: (array([14], dtype=int64),)
In: type(distance_index)
Out: tuple
So, my question is simple...I need to grab the value of 14 from the array so that I can use it in another part of the code. 所以,我的问题很简单...我需要从数组中获取14的值,以便可以在代码的另一部分中使用它。
To get any index of your array just use "array[index]". 要获取数组的任何索引,只需使用“ array [index]”。 Keep in mind arrays start at 0
请记住,数组从0开始
print(distance_index[0])
However, as @Christian Dean points out, this question deals with an array in a tuple. 但是,正如@Christian Dean指出的那样,此问题涉及元组中的数组。 So you need:
因此,您需要:
print(distance_index[0][0])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.