DiamondMatrix
✖
DiamondMatrix
gives a matrix whose elements are 1 in a diamond-shaped region that extends r index positions to each side, and are 0 otherwise.
yields an array whose elements are 1 in a diamond-shaped region that extends ri index positions in the i direction.
Details

- The diamond of 1s is always at the center of the region.
- In DiamondMatrix[r] or DiamondMatrix[{r1,…}] the matrix or array is sized so as to just include all nonzero elements.
- The region of 1s is taken to be the best discrete approximation to a diamond-shaped region possible given the size of the matrix.
- DiamondMatrix[All,w] gives a w×w matrix containing a diamond shape that is as large as possible.
- DiamondMatrix[…,{w1,w2,…}] gives a w1×w2×… array.
- DiamondMatrix[{r1,…,rn},w] gives a w×…×w array.
- DiamondMatrix[All,{w1,…,wn}] gives a w1×…×wn array containing a diamond-shaped region that is as large as possible.
- The parameter r need not be an integer; in general elements are 1 if their Manhattan distance from the center is not more than
.
- For integer r, DiamondMatrix[r] yields a
matrix.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Scope (5)Survey of the scope of standard use cases
Create a rectangular diamond-shaped matrix:

https://wolfram.com/xid/0i1ovah66-qpi35b

Put a diamond inside a bigger matrix:

https://wolfram.com/xid/0i1ovah66-xjedjo

Extend the diamond to the boundaries of the matrix:

https://wolfram.com/xid/0i1ovah66-qazkdu

Automatically choose an odd width to just fit the diamond:

https://wolfram.com/xid/0i1ovah66-145bbn

Extend the diamond to the given width, and automatically choose the height:

https://wolfram.com/xid/0i1ovah66-fultpq

Wolfram Research (2008), DiamondMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/DiamondMatrix.html.
Text
Wolfram Research (2008), DiamondMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/DiamondMatrix.html.
Wolfram Research (2008), DiamondMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/DiamondMatrix.html.
CMS
Wolfram Language. 2008. "DiamondMatrix." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DiamondMatrix.html.
Wolfram Language. 2008. "DiamondMatrix." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DiamondMatrix.html.
APA
Wolfram Language. (2008). DiamondMatrix. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DiamondMatrix.html
Wolfram Language. (2008). DiamondMatrix. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DiamondMatrix.html
BibTeX
@misc{reference.wolfram_2025_diamondmatrix, author="Wolfram Research", title="{DiamondMatrix}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/DiamondMatrix.html}", note=[Accessed: 29-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_diamondmatrix, organization={Wolfram Research}, title={DiamondMatrix}, year={2008}, url={https://reference.wolfram.com/language/ref/DiamondMatrix.html}, note=[Accessed: 29-April-2025
]}