The Maxima on-line user's manual

Algebra Calculator

Fillarray

Function: fillarray (<A>, <B>) Fills array <A> from <B>, which is a list or an array.

If a specific type was declared for <A> when it was created, it can only be filled with elements of that same type; it is an error if an attempt is made to copy an element of a different type.

If the dimensions of the arrays <A> and <B> are different, <A> is filled in row-major order. If there are not enough elements in <B> the last element is used to fill out the rest of <A>. If there are too many, the remaining ones are ignored.

`fillarray` returns its first argument.

Examples:

```     Create an array of 9 elements and fill it from a list.
(%i1) array (a1, fixnum, 8);
(%o1)                          a1
(%i2) listarray (a1);
(%o2)              [0, 0, 0, 0, 0, 0, 0, 0, 0]
(%i3) fillarray (a1, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
(%o3)                          a1
(%i4) listarray (a1);
(%o4)              [1, 2, 3, 4, 5, 6, 7, 8, 9]```

When there are too few elements to fill the array, the last element is repeated. When there are too many elements, the extra elements are ignored.

`          (%i1) a2 : make_array (fixnum, 8);`
`          (%o1)             {Array:  #(0 0 0 0 0 0 0 0)}`
`          (%i2) fillarray (a2, [1, 2, 3, 4, 5]);`
`          (%o2)             {Array:  #(1 2 3 4 5 5 5 5)}`
`          (%i3) fillarray (a2, [4]);`
`          (%o3)             {Array:  #(4 4 4 4 4 4 4 4)}`
`          (%i4) fillarray (a2, makelist (i, i, 1, 100));`
`          (%o4)             {Array:  #(1 2 3 4 5 6 7 8)}`

```     Multple-dimension arrays are filled in row-major order.
(%i1) a3 : make_array (fixnum, 2, 5);
(%o1)        {Array:  #2A((0 0 0 0 0) (0 0 0 0 0))}
(%i2) fillarray (a3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
(%o2)        {Array:  #2A((1 2 3 4 5) (6 7 8 9 10))}
(%i3) a4 : make_array (fixnum, 5, 2);
(%o3)     {Array:  #2A((0 0) (0 0) (0 0) (0 0) (0 0))}
(%i4) fillarray (a4, a3);
(%o4)     {Array:  #2A((1 2) (3 4) (5 6) (7 8) (9 10))}```

```(%o1)                                true
(%i2) ```

? fillarray;

Calculate

? fillarray;

Calculate