Listable
is an attribute that can be assigned to a symbol to indicate that the function should automatically be threaded over lists that appear as its arguments.
Details
- Listable functions are effectively applied separately to each element in a list, or to corresponding elements in each list if there is more than one list.
- Most built‐in mathematical functions are Listable. »
- All the arguments which are lists in a Listable function must be of the same length. »
- Arguments that are not lists are copied as many times as there are elements in the lists.
Examples
open allclose allBasic Examples (4)
Scope (4)
Define a function to be listable:
Most built-in mathematical functions are listable:
Listability works for any nesting depth of lists:
The nesting level of the different arguments need not be the same:
Listability works on other list-like constructs such as SparseArray:
Applications (2)
To apply a function to a vector, take advantage of Listable functions when possible:
Use the listability of Plus, Power, Sin, and Times:
Use Map:
Use Table:
Use Table and Part to access elements of v as might be done in a lower-level language:
The results are the same up to numerical roundoff:
Use efficient sparse arithmetic to numerically solve the heat equation :
Matrix for a second-order approximation to the second derivative on the grid :
Incorporate Dirichlet boundary conditions to form the Jacobian J:
Form sparse matrix for using the listability of arithmetic:
LU decomposition of in a functional form:
Step initial condition on spatial grid x using the listability of UnitStep:
Properties & Relations (7)
Listable, in general, functions effectively apply Thread many times:
Applying listable functions to several arrays of equal dimension is equivalent to using MapThread:
Listable functions applied to several arrays require overlapping dimensions to be equal:
Arguments with equal dimensions:
Arguments with equal overlapping dimensions, i.e. {2} has the same leading dimensions as {2,3}:
Arguments with unequal overlapping dimensions, i.e. {2} does not have the same leading dimensions as {3,2}:
Listable functions applied to arrays can be written as a Table:
A function implemented in terms of a listable operation may not need the Listable attribute:
The system symbols with the Listable attribute:
More than half these are arithmetic functions possessing the NumericFunction attribute as well:
The products given by Dot, Times, and KroneckerProduct are inner, element-wise, and outer:
The inner product of two vectors:
The vector resulting from the product of corresponding elements:
Text
Wolfram Research (1988), Listable, Wolfram Language function, https://reference.wolfram.com/language/ref/Listable.html.
CMS
Wolfram Language. 1988. "Listable." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Listable.html.
APA
Wolfram Language. (1988). Listable. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Listable.html