# Classifying broadcasting in math/array, and a question about array-append\* and array-list-\>array

**URL:** <https://racket.discourse.group/t/classifying-broadcasting-in-math-array-and-a-question-about-array-append-and-array-list-array/3999>\
**Category:** General\
**Tags:** arrays-proposal\
**Created:** [November 8, 2025, 1:25am UTC](https://racket.discourse.group/t/classifying-broadcasting-in-math-array-and-a-question-about-array-append-and-array-list-array/3999 "2025-11-08T01:25:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gambiteer](https://avatars.discourse-cdn.com/v4/letter/g/779978/32.png) [@Gambiteer](https://racket.discourse.group/u/Gambiteer)\
**Post date:** [November 8, 2025, 1:25am UTC](https://racket.discourse.group/t/classifying-broadcasting-in-math-array-and-a-question-about-array-append-and-array-list-array/3999/1 "2025-11-08T01:25:30Z")

</div>

I think I can classify the purpose of array broadcasting in almost every routine in `math/array` that uses it, and can compare it with the use in Python's NumPy library (of which I am also no expert).

`array-map`: The basic element-by-element function application, exactly as in NumPy. (As far as I can tell, this is the only use of broadcasting in NumPy, but the technique is very powerful there.)

`array-ormap`, `array-andmap`: Because `array-ormap` and `array-andmap` can short-circuit, these routines `array-map` the `pred?` argument to the array arguments while ensuring that the strictness parameter is `#f`. They avoid the user doing `(array-map pred? array ...)` with the strictness parameter being `#t`, which would evaluate `pred?` on all elements, and not take advantage of the short-circuiting.

`array-count`: Does something similar, applying `array-all-sum` to an `array-map` of `(lambda (x) (if x 1 0))` to an `array-map` of `pred?` to the array arguments with the strictness parameter set to `#f`. This is an iterated `array-map`, and defining `array-count` in this way ensures that two intermediate arrays are not allocated in memory.

I'm having difficulty seeing the utility of automatic broadcasting of array arguments to `array-append*` and `array-list->array`. It leads to the following behavior (with some hand editing):

```scheme
(require math/array)

> (array-append* (list (array #[#[0 1] #[2 3]]) (array #['a]) (array #['A 'B])) 0)
(array #[#[0 1]
         #[2 3]
         #['a 'a]
         #['A 'B]])
> (array-append* (list (array #[#[0 1] #[2 3]]) (array #['a]) (array #['A 'B])) 1)
(array #[#[0 1 'a 'A 'B]
         #[2 3 'a 'A 'B]])

> (array-list->array (list (array #[#[0 1] #[2 3]]) (array #['a]) (array #['A 'B])) 0)
(array #[#[#[0 1]
           #[2 3]]
         #[#['a 'a]
           #['a 'a]]
         #[#['A 'B]
           #['A 'B]]])
> (array-list->array (list (array #[#[0 1] #[2 3]]) (array #['a]) (array #['A 'B])) 1)
(array #[#[#[0 1]
           #['a 'a]
           #['A 'B]]
         #[#[2 3]
           #['a 'a]
           #['A 'B]]])
> (array-list->array (list (array #[#[0 1] #[2 3]]) (array #['a]) (array #['A 'B])) 2)
(array #[#[#[0 'a 'A]
           #[1 'a 'B]]
         #[#[2 'a 'A]
           #[3 'a 'B]]])

```

I understand the results, and why they are what they are, but I don't see the general utility of it.

Also, `array-append*` needs a special case of array broadcasting, in which it (quite naturally) does not broadcast along axis `k` when appending along axis `k`.

I've searched GitHub for all instances of `array-append*` and `array-list->array` in Racket code, but I could not see whether any uses of these routines took advantage of the implicit broadcasting of array arguments.

So, the question: Can anyone point me to examples of code using these routines while taking advantage of implicit broadcasting? Or to point out applications where this might be natural or useful?
