Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia, parsimonious way to create Int8 array of 3's?

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.

like image 519
Jim Maas Avatar asked Dec 04 '25 10:12

Jim Maas


1 Answers

@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)
like image 89
Benoit Pasquier Avatar answered Dec 06 '25 22:12

Benoit Pasquier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!