Seems simple but I can't figure it out. What is the simplest way in Julia to create a new array of type Int8, containing ten 3's ? Thx. J
Obviously
Int8[3,3,3,3,3,3,3,3,3,3]
works but I want to produce much larger arrays.
@mcabbott's suggestion
fill(Int8(3), 10)
was my first thought and the best choice IMHO, but you can also do one of these if your preference goes to any of them
[Int8(3) for _ in 1:10]
or
Int8.(3 * ones(10))
or
Int8(3) * ones(Int8, 10)
[EDIT] or (Oscar Smith suggestion)
Int8(3) .+ zeros(Int8, 10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With