首页 > 其他 > 详细

numpy学习(一)

时间:2019-09-23 22:15:20      阅读:116      评论:0      收藏:0      [点我收藏+]

(一)基础学习

学习渠道:阿里天池AI学习——Numpy基础(传送门

 

(二)练习篇

练习渠道:Numpy基础100题(Part 1)

1. Import the numpy package under the name np(★☆☆)

1 import numpy as np 

2. Print the numpy version and the configuration(★☆☆)

1 print(np.version)
2 np.show_config()

3. Create a null vector of size 10(★☆☆)

1 arr = np.zeros(10)
2 print(arr)

运行结果:[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

4. How to find the memory size of any array (★☆☆)

1 print("%d bytes" %(arr.size*arr.itemsize))

运行结果:80 bytes

5. How to get the documentation of the numpy add function from the command line? (★☆☆)

np.add?

6. Create a null vector of size 10 but the fifth value which is 1 (★☆☆)

1 arr = np.zeros(10)
2 arr[4] = 1;
3 print(arr)

运行结果:[0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]

7. Create a vector with values ranging from 10 to 49 (★☆☆)

1 arr = np.arange(10,50)
2 print(arr)

运行结果:[10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]

8. Reverse a vector (first element becomes last) (★☆☆)

1 arr = np.arange(10,50)
2 print(arr[::-1])

运行结果:[49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10]

9. Create a 3x3 matrix with values ranging from 0 to 8 (★☆☆)

1 arr = np.arange(9).reshape(3,3)
2 print(arr)

运行结果:[[0 1 2] [3 4 5] [6 7 8]]

10. Find indices of non-zero elements from [1,2,0,0,4,0] (★☆☆)

1 arr = np.array([1,2,0,0,4,0])
2 print(arr.nonzero()[0])

运行结果:[0 1 4]

 

numpy学习(一)

原文:https://www.cnblogs.com/orangecyh/p/11574551.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!