zip - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


zip

zip together two lists, matrices, or vectors

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

zip(f, u, v)

zip(f, u, v, d)

zip[dense]( f, u, v, d )

zip[sparse]( f, u, v, d )

zip[inplace]( f, u, v, d )

zip[evalhf]( f, u, v, d )

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 nonzero 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.

• 

The inplace option only applies when u and v are both rtables of the same size, storage, and data type.  When this option is used, u will be modified in-place.  

• 

The evalhf option only applies when u and v are both rtables of data type float[8] or complex[8]. When this option is used, evaluation of f will be done using the evalhf subsystem.  

Examples

zipx,yx+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+3&comma;x2+3

3&comma;x2

(5)

zipx&comma;yx+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;yx+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=antisymmetric

b0000

(9)

b1,23

b1,23

(10)

zipx&comma;yx+y&comma;a&comma;b

26813

(11)

zipx&comma;yx+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;yyx&comma;c&comma;d

3005

(14)

fVector3&comma;5

f555

(15)

gVectorrow1&comma;2

g12

(16)

zipx&comma;yxy&comma;f&comma;g&comma;10

43−5

(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)

Compatibility

• 

The zip command was updated in Maple 2021.

• 

The inplace and evalhf options were introduced in Maple 2021.

• 

For more information on Maple 2021 changes, see Updates in Maple 2021.

See Also

Array

LinearAlgebra[Zip]

map

Matrix

operators,elementwise

Vector