In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what is the difference between np.array() and np.asarray in numpy", the content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn "what is the difference between np.array() and np.asarray in numpy".
Both array and asarray can convert structured data to ndarray, but the main difference is that when the data source is ndarray, array will still copy a copy, taking up new memory, but asarray will not.
1. When the input is a list, a=[[1,2,3],[4,5,6],[7,8,9]]b=np.array(a)c=np.asarray(a)a[2]=1print(a)print(b)print(c)
From this we can see that np.array and np.asarray function is the same, both input into matrix format. When the input is a list, changing the values of the list does not affect the values converted to the matrix.
2. When the input is array, a=np.random.random((3,3))print(a.dtype)b=np.array(a,dtype='float64')c=np.asarray(a,dtype='float64')a[2]=2print(a)print(b)print(c)
From the above results we can see the difference between np.array and np.asarray, which is that np.array copies the input and np.asarray cuts the input, so the output of np.array does not change as the input changes, while the output of np.asarray changes, and when we change the type of np. asarray (input float64 to float32), so that when the input changes, the output of np.asarray does not change.
3, array type to list type a=np.random.random((3,3))print(a.dtype)b=a.tolist()a[1]=2print(a)print(b)
From the above we can see that.tolist is to convert an array to a list format, which is equivalent to the inverse of np.array, so under what circumstances do you need to convert np.ndarray to a list format? When serialization is required, np.ndarray is not serializable.
What is the difference between np.array() and np.asarray in numpy? Thank you for reading all the contents of this article! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to 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.