To illustrate what I mean, consider the following:
SparseArray[{{1} -> 1, {5} -> 1.}, Automatic, 0] // Normal
{1, 0, 0, 0, 1.}
As you can see, the distinction between 1 and 1. is preserved. Now consider:
SparseArray[{{1} -> 1, {5} -> 1.}, Automatic, 1] // Normal
{1, 1, 1, 1, 1}
In this situation, the 1. has been absorbed into the background value 1 and the distinction disappears.
There seems to be one way to do what I want, which is this:
one = 1.;
SparseArray[Unevaluated @ {{1} -> 1, {5} -> one}, Automatic, 1] // Normal
{1, 1, 1, 1, 1.}
However, this makes the list of rules very tricky to manipulate, since the one can evaluate away very easily if you're not careful about holding the evaluation. Is there a better way to do this?
Edit
Just to be clear: I'm not interested in generating the list {1, 1, 1, 1, 1.} by itself. What I'm interested in, is having a SparseArray object that holds a background value of 1 and has 1. among it's specified elements.
Also: these evaluations were done on V12.3
{1, 1, 1, 1, 1.}. – kglr Dec 02 '21 at 10:38Normal[SparseArray[{{1} -> 1, {5} -> 1.}, Automatic, 1.]]returns{1., 1., 1., 1., 1.}(version 12.0) and I find it quite convenient. – Henrik Schumacher Dec 02 '21 at 11:42SparseArray[{{1} -> 1, {5} -> 1.}, Automatic, 1] // Normalevaluates to{1, 1, 1, 1, 1}, too. So together with kglr's comment we have quite exactly pinned down when this behavior was changed. – Henrik Schumacher Dec 02 '21 at 11:43Around[1,$MachineEpsilon]be an alternative to1.0for your application? – rhermans Dec 09 '21 at 09:39