In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to convert data to int type in python numpy.ndarray", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to convert data into int type in python numpy.ndarray" article.
The data in numpy.ndarray is converted to int.
First, understand the content and type.
> > print (a) (array ([[0.01124722], [0.21752586], [0.05586815], [0.03558792]), array ([[327,366,1887], [1153,1792]]) Dtype=int64) > print (type (a)) > > print (a [1]) [[327] [366] [1887] [1153] [1792]] > > print (type (a [1]))
Next, you can iterate through a [1] and convert each element to int with list () and tolist (), as follows:
For i in a [1]: B = list (I) [0] .tolist ()
First change to the list type with list (), and [0] means to get the first value (in fact, there is only one value), then the type is numpy.int64, and then it is converted to int with tolist ().
The data in numpy.ndarray is converted to int.
Error only size-1 arrays can be converted to Python scalars occurred
After analysis, it is found that it is the error of the data type.
The original data is [63], and the data type obtained by using type is:
So change the ndarray type of numpy to int (or the type you need, here is int)
Using the method of list (m) [0] .tolist (), the result is as follows
sixty-three
Ok, the problem was solved successfully.
The above is about the content of this article on "how to convert data to int in python numpy.ndarray". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.