zip - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Flow Control : Iteration or Looping : zip

zip

zip together two lists, matrices, or vectors

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

zip(f, u, v)

zip(f, u, v, d)

zip[dense]( ... )

zip[sparse]( ... )

Parameters

f

-

binary function

u, v

-

lists, rtables, Arrays, Matrices, Vectors, or scalars

d

-

(optional) value

Description

• 

The function zip applies the binary function f to the components of two data sets u and v, creating a new data set r defined as follows.  If m is the length of u and n is the length of v then r is a data set of length minm,n with ri=fui,vi for i in 1..minm,n.

• 

If u and v are Matrices of the same size, then zip applies the binary function f to the pairs of corresponding entries of the matrices u and v. The i,j-entry of the resulting matrix is fui,j,vi,j.

• 

If u and v are not both rtables, Arrays, or lists (ie. both are scalars) then fu,v is returned. If only u is a scalar then map2f,u,v is computed. If only v is a scalar then mapf,u,v is returned. In other words, zipping a matrix against a scalar is the same as zipping against a same-size matrix filled with that scalar at each entry.

• 

If the optional fourth argument d is given, it is used as a default value for f when one of the data sets is shorter than the other. Thus r is a data set of length maxm,n with ri=fui,vi for i in 1..minm,n and ri=fti,d for i in 1+minm,n..maxm,n where t is the longer of u and v.

• 

If u and v are Matrices of the same size, then the optional fourth argument is accepted, but ignored.  Similarly, if either u or v are not matrices then the fourth argument is also ignored.

• 

If u and v are not Matrices of the same size, then the size of the result is determined by the presence or absence of the optional fourth parameter. If this parameter is omitted in the calling sequence then the result object's dimensions are determined by taking the minimum of the corresponding dimensions of u and v.

• 

The sparse and dense options control how zip is applied to zero data in sparse storage Arrays, Vectors, and Matrices.  The zip[sparse] command will apply f for each matched element in the array provided they are not both zero.  This scans the actual stored entries (zeros are not stored in sparse arrays).  The zip[dense] command will apply f for every matched element in the result index space, as if both input arrays were dense. By default sparse Array inputs, where f(0,0) is non-zero will have the zip[dense] algorithm applied.  Sparse Matrix and Vector inputs will have the zip[sparse] algorithm applied by default.  The zip[sparse] algorithm is used by default when zipping a sparse matrix against a scalar.

• 

An in-place version of zip is available for Vectors and Matrices, via the LinearAlgebra[Zip] routine.

Examples

zipx,y→x+y,1,2,3,4,5,6

5,7,9

(1)

zipgcd,0,14,8,2,6,12

2,2,4

(2)

zipcat,trap,hill,door,side

trapdoor,hillside

(3)

zip`>`,x,y,4,2

4<x&comma;2<y

(4)

zipop&comma;2&comma;1&comma;x2&plus;3&comma;x2&plus;3

3&comma;x2

(5)

zipx&comma;y&rarr;x&plus;y&comma;1&comma;2&comma;3&comma;4&comma;5&comma;0

5&comma;7&comma;3

(6)

aMatrix2&comma;3&comma;1&comma;2&comma;3&comma;4&comma;5&comma;6&colon;

bMatrix2&comma;3&comma;1&comma;3&comma;5&comma;7&comma;9&comma;2&colon;

zipx&comma;y&rarr;x&plus;y&comma;a&comma;b

25811148

(7)

zip`+`&comma;a&comma;b

25811148

(8)

aMatrix3&comma;4&comma;2&comma;3&comma;5&comma;7&comma;11&comma;13&comma;17&comma;19&comma;23&comma;29&comma;31&comma;37&colon;

bMatrix2&comma;2&comma;shape&equals;antisymmetric

b:=0000

(9)

b1&comma;23

b1&comma;2:=3

(10)

zipx&comma;y&rarr;x&plus;y&comma;a&comma;b

26813

(11)

zipx&comma;y&rarr;x&plus;y&comma;b&comma;a&comma;1

2646813161822283036

(12)

zip`+`&comma;a&comma;100

102103105107111113117119123129131137

(13)

cArray1&comma;0&comma;0&comma;1&colon;

dMatrix2&comma;2&comma;3&comma;0&comma;2&comma;5&colon;

zipx&comma;y&rarr;xy&comma;c&comma;d

3005

(14)

fVector3&comma;5

f:=555

(15)

gVector&lsqb;row&rsqb;1&comma;2

g:=12

(16)

zipx&comma;y&rarr;xy&comma;f&comma;g&comma;10

435

(17)

To use the list constructor as the function to apply, enter back quotes around [].

zip`[]`&comma;1&comma;2&comma;3&comma;4&comma;5&comma;6

1&comma;4&comma;2&comma;5&comma;3&comma;6

(18)

See Also

Array

LinearAlgebra[Zip]

map

Matrix

operators,elementwise

Vector

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam