码迷,mamicode.com
首页 > 编程语言 > 详细

利用python 学习数据分析 (学习二)

时间:2019-01-12 13:19:09      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:res   https   切片   python 学习   target   sha   假设   yun   http   

内容学习自:

Python for Data Analysis, 2nd Edition        

就是这本技术分享图片

纯英文学的很累,对不对取决于百度翻译了

前情提要:

各种方法贴:

  https://www.cnblogs.com/baili-luoyun/p/10250177.html

    本内容主要讲的是:

      继续数组和矢量

   一:花式索引

      定义:花式索引指的是利用整数进行索引,

      假设我们有一个 8 *4的数组

arr = np.empty([8,4])
print(arr)#传入的元祖或者列表
for i in range(8):
    arr[i] =i
print(arr)
>>>>>

[[4.67296746e-307 1.69121096e-306 1.29061074e-306 1.69119873e-306]
[1.78019082e-306 3.56043054e-307 7.56595733e-307 1.60216183e-306]
[8.45596650e-307 1.86918699e-306 1.78020169e-306 6.23054633e-307]
[1.95821439e-306 8.01097889e-307 1.78020169e-306 7.56601165e-307]
[1.02359984e-306 1.29060531e-306 1.24611741e-306 1.11261027e-306]
[7.56591659e-307 1.33511290e-306 6.89804133e-307 1.20160711e-306]
[6.89806849e-307 8.34446411e-308 1.22383391e-307 1.33511562e-306]
[1.42410974e-306 1.00132228e-307 1.33511969e-306 2.18568966e-312]]

>>>>> 赋值转换成这个

[[0. 0. 0. 0.]
[1. 1. 1. 1.]
[2. 2. 2. 2.]
[3. 3. 3. 3.]
[4. 4. 4. 4.]
[5. 5. 5. 5.]
[6. 6. 6. 6.]
[7. 7. 7. 7.]]

 

      然后我拿 [3,4,5,4] 行

arr1 =arr[[3,4,5,4]]
print(arr1)
>>>>>
[[0. 0. 0. 0.]
 [1. 1. 1. 1.]
 [2. 2. 2. 2.]
 [3. 3. 3. 3.]
 [4. 4. 4. 4.]
 [5. 5. 5. 5.]
 [6. 6. 6. 6.]
 [7. 7. 7. 7.]]

>>>>                 [3,4,5,4]      拿3  4  5  4 行
[[3. 3. 3. 3.]
 [4. 4. 4. 4.]
 [5. 5. 5. 5.]
 [4. 4. 4. 4.]]

 

      可以按照索引倒着拿  这次我拿 -1  -2  -3

arr2 =arr[[-1,-2,-3]]
print(arr2)

>>>>>>>>>>>>


[[0. 0. 0. 0.]
 [1. 1. 1. 1.]
 [2. 2. 2. 2.]
 [3. 3. 3. 3.]
 [4. 4. 4. 4.]
 [5. 5. 5. 5.]
 [6. 6. 6. 6.]
 [7. 7. 7. 7.]]


>>>>>>>>>>


[[7. 7. 7. 7.]
 [6. 6. 6. 6.]
 [5. 5. 5. 5.]]

 

       多维数组中拿到具体某行某列中的值

       :>1 索引

      :拿第1 ,4,3,2 行之后 ,拿第一行的0索引,第4行的第4个索引....

arr1 =np.arange(1,31).reshape(6,5)      #指定范围1,31 内的  以6行5列显示
l1 =arr1[[1,4,3,2],[0,4,3,4]]
print(arr1)
print(l1)

>>>>>>

[[ 1 2 3 4 5]
[ 6 7 8 9 10]
[11 12 13 14 15]
[16 17 18 19 20]
[21 22 23 24 25]
[26 27 28 29 30]]

 

>>>>>>>>
[ 6 25 19 15]

 

         >2:切片

        

 

利用python 学习数据分析 (学习二)

标签:res   https   切片   python 学习   target   sha   假设   yun   http   

原文地址:https://www.cnblogs.com/baili-luoyun/p/10259303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!