Search
Star
Feedback
Setup for Free
© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
How to initialize a tensor[DType.int8] with random values of either: -1, 0, or 1? - Modular
M
Modular
•
2y ago
•
15 replies
null
How to initialize a tensor[DType.int8] with random values of either: -1, 0, or 1?
Probably a dumb question
, but how can I initialize a Tensor like so with random values of either
-1
, 0
, or 1
?
var a = Tensor[DType.int8](size)
var a = Tensor[DType.int8](size)
The rand functions I could find either don
't let me specify the range
, or work for other data types
.
Furthermore
, is this really only for SIMD compatible sizes
? Like what if I wanted it to have 10
,000 elements
? Is Tensor the wrong data type for this
?
I want to perform element
-wise vector operations on it later
, like xor
(vector
_a
, vector
_b
)
- but in a highly parallel way
Modular
Join
This server is the home of the MAX and Mojo community! Join us to chat about all things Modular.
20,199
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Similar Threads
Populating values of tensor
M
Modular / questions
3y ago
`tensor.tensor.Tensor`, `max.tensor.Tensor` or `max.driver.Tensor`?
M
Modular / questions
15mo ago
Range of SIMD[DType, 1]
M
Modular / questions
3y ago
Why is the dtype of `String`'s underlying storage `int8` and not `uint8`?
M
Modular / questions
3y ago