Created
September 3, 2018 14:30
array_operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# arrayモジュールの使い方 | |
import array as ar | |
#型指定が必要 | |
#ベクトルしか表現できない | |
ar_int = ar.array("i",[1 , 2 , 3 , 4 ]) # 中身をint型で指定 | |
ar_float = ar.array("f",[1.0 , 2.0 , 3.0 , 4.0]) # 中身をfloat型で指定 | |
type(ar_int) #array.array型 | |
type(ar_float) #array.array型 | |
# 基本的にlistと同じ | |
ar_int[1] # 2 | |
ar_int+ar_int # array('i', [1, 2, 3, 4, 1, 2, 3, 4]) | |
max(ar_int) # 4 | |
min(ar_int) # 1 | |
sum(ar_int) # 10 | |
len(ar_int) # 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment