zip
zip together two lists, matrices, or vectors
Calling Sequence
Parameters
Description
Examples
Compatibility
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 )
f
-
binary function
u, v
lists, rtables, Arrays, Matrices, Vectors, or scalars
d
(optional) value
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 min⁡m,n with ri=f⁡ui,vi for i in 1..min⁡m,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 f⁡ui,j,vi,j.
If u and v are not both rtables, Arrays, or lists (ie. both are scalars) then f⁡u,v is returned. If only u is a scalar then map2⁡f,u,v is computed. If only v is a scalar then map⁡f,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 max⁡m,n with ri=f⁡ui,vi for i in 1..min⁡m,n and ri=f⁡ti,d for i in 1+min⁡m,n..max⁡m,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.
zip⁡x,y↦x+y,1,2,3,4,5,6
5,7,9
zip⁡gcd,0,14,8,2,6,12
2,2,4
zip⁡cat,trap,hill,door,side
trapdoor,hillside
zip⁡`>`,x,y,4,−2
4<x,−2<y
zip⁡op,2,1,x2+3,x2+3
3,x2
zip⁡x,y↦x+y,1,2,3,4,5,0
5,7,3
a≔Matrix⁡2,3,1,2,3,4,5,6:
b≔Matrix⁡2,3,1,3,5,7,9,2:
zip⁡x,y↦x+y,a,b
25811148
zip⁡`+`,a,b
a≔Matrix⁡3,4,2,3,5,7,11,13,17,19,23,29,31,37:
b≔Matrix⁡2,2,shape=antisymmetric
b≔0000
b1,2≔3
26813
zip⁡x,y↦x+y,b,a,−1
2646813161822283036
zip⁡`+`,a,100
102103105107111113117119123129131137
c≔Array⁡1,0,0,1:
d≔Matrix⁡2,2,3,0,2,5:
zip⁡x,y↦y⋅x,c,d
3005
f≔Vector⁡3,5
f≔555
g≔Vectorrow⁡1,2
g≔12
zip⁡x,y↦x−y,f,g,10
43−5
To use the list constructor as the function to apply, enter back quotes around [].
zip⁡`[]`,1,2,3,4,5,6
1,4,2,5,3,6
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
Download Help Document