MathematicaのList表現

関数のList適用可能性

list 内の要素の関数を作用できるような関数属性を Listable.  
関数属性を返す　Attributes[ ] と属性をセットする SetAttributes[ ]

f[x_] := x^2;

Attributes[f]

f[{a,b,c,d}]

SetAttributes[f, Listable]

f[{a, b, c, d}]

List

{2, 3, 4}

x^% +1

% /. x -> 2

Listを作るTable[ ]

Table[i^2, {i, 1, 8}]

Table[RandomReal[], {i, 1, 10}]

m = Table[i j, {i, 1, 4}, {j, 1, 3}]

リスト要素のアクセス

m[[1]]

m[[2,2]]

Part[m, {1,2}]

m[[{1,2}]]

m[[1;;2]]

m[[2;;4]]

TableForm[m]

m //TableForm

m //MatrixForm

m2=Table[i j^2 k^3, {i, 1,2}, {j, 1, 2}, {k, 1, 2}]

m2[[1]]

m2[[1]][[2]]

Flatten[m2]

Length[m2]

Array[a, 3]

a[x_] := Sin[x]

Array[a, 4]

N[%]

Attributes[N]

Range[4]

Range[5,10]

Array[a, {2,3}]

Array[a, {2,2,3}]

部分Listの操作

t1=Table[i j^2, {i, 1, 4}, {j, 1, 5}]

First[t1]

Last[t1]

Part[t1, -2]

Part[t1,{2,3}]

Part[t1, 2,3]

Extract[t1, {2,3}]

Extract[t1, {{2,3},{3,1}}]

Take[t1, 2]

Take[t1, -2]

Rest[t1]

Drop[t1, 2]

Drop[t1, -2]

y=Sum[x^i, {i, 0, 5}]

Take[y, 3]

Length[y]

Part[y, 3]

Part[y, {2 ,3}]

Position[y, x]

FullForm[y]

Listの要素

Position[t={a,b,c,a,d,{e, a},a,d,b}, a]

Count[t, a]

MemberQ[t, f]

FreeQ[t, f]

Position[t, a]

Extract[t, Position[t, a]]

Prepend[t, x]

Append[t, {y,z}]

t

Insert[t, w , 2]

Insert[t, q, -2]

Delete[t, -2]

t

ReplacePart[t, x, Position[t, a]]

Listの分割

Partition[{a,b,c,d,e,f,g}, 2]

Partition[{a,b,c,d,e,f,g}, 3]

Partition[{a,b,c,d,e,f,g}, 2,1]

Partition[{a,b,c,d,e,f,g}, 2,2]

Partition[{a,b,c,d,e,f,g}, 2,4]

Partition[{a,b,c,d,e,f,g}, 3, 1]

Partition[{a,b,c,d,e,f,g}, 3, 2]

Partition[{a,b,c,d,e,f,g}, 3, 4]

Listの結合 Join と集合操作

Join[{a,b,c}, {d,{e,f},g},{h,i}]

Union[{a,b,c},{a, d},{e,f,b}]

Union[{a, {a,b}}, {c, {a,b}},{d}]

Intersection[{a,b,c},{b,c,d,f}]

Complement[{a,b,c,d,e,f,{a,b}}, {a,d, e}]

Listの順序

Reverse[{a,b,c,d,e}]

RotateLeft[{a,b,c,d,e}]

Permutations[{a,b,c}]

Outer[List,{a,b,c},{x,y}]