Day4 - numpy(3) 布林索引、转置阵列

布林索引:
布林索引就是在索引里放入布林阵列,为True的值会被挑出来
一样先建立一个ndarray来让我们实际操作
https://ithelp.ithome.com.tw/upload/images/20210823/20140416odthj3dcf3.png

先看布林阵列的产生
我们想要知道阵列里资料是否小於10
https://ithelp.ithome.com.tw/upload/images/20210823/20140416BBrfm5u9ZG.png

之後放入索引
https://ithelp.ithome.com.tw/upload/images/20210823/20140416bGiQInkFyG.png
我们就获得了小於10的数值

布林索引也能与python的关键字and、not、or一起使用
可是在布林索引时必须打符号 &、!、| 否则会报错
错误写法:
https://ithelp.ithome.com.tw/upload/images/20210823/20140416o603qO818d.png
正确写法:
https://ithelp.ithome.com.tw/upload/images/20210823/20140416ZhuzLtwPaL.png
以上是简单的布林索引操作,布林索引很有利於我们之後索取资料使用

转置阵列:
转置阵列就是改变阵列的shape
我可以使用reshape()这个方法做到,参数是传入想改变成的shape之tuple
https://ithelp.ithome.com.tw/upload/images/20210823/20140416jHwoovDyqZ.png

这里还有一个很酷的方式 就是在reshape後面的参数填上-1 它会自动变成符合资料的模样
https://ithelp.ithome.com.tw/upload/images/20210823/20140416ptxbg5aAxq.png

今天焦点整理:
布林索引及ndarray.shape的改变方式

送上colab连结,可自行在上面多做点练习更加熟悉numpy
https://colab.research.google.com/drive/1MM0JALWhWG4sJSg0D-djF6qgeLfdP3Go?usp=sharing


<<:  [Angular] Day6. Sharing data between child and parent directives and components

>>:  Day06,将昨日的静态页面打包

D-27-变数 variable ? int ? string

认识变数 variable 在昨天的历程中小光学习到如何透过dotnet cli来产生专案跟方案,并...

C# 入门笔记01

程序架构 Namespace (自订命名空间) 就是由自己写的程序库之名称,一个程序库只能有一个自订...

DAY25 - [React hook] props

今日文章目绿 前言 实作需求 过程纪录 参考资料 昨天讲到component零组件组装的方法,但没...

Day27-移动侦测1

在开始编写程序之前,让我们先汇入必要的函式库。 import cv2 import numpy as...

[Day 27 - 小试身手] Todolist with React (2)

在上一章Todolist with React (1),建立了专案环境、并且拆离 UI 设定好所有...