How can I assign to a variable an f64?

Hi

How can I assign to a variable an an empty f64 using https://docs.rs/crate/numpy/0.7.0 or https://docs.rs/crate/ndarray/0.12.1 depending on which one would be the best to use for this.

Thanks

What do you mean? Those two libraries do different things, one exposes a python C API, and the other lets you declare multidimensional arrays...

Neither have anything to do with assigning to an f64.

let x: f64;
x = 2.0; //This is assignment to an f64

I want to create a variable with a numpy float rather than a normal float. This is because in python numpy you can assign a variable to np.float64. I was wondering what would be the equivalent in rust.

I would suggest just simulating a call to numpy.float64. (i.e. import the numpy module, and call its float64 method). You should try to keep the output as a PyObject in the rust code rather than converting it to f64. The precise way to do this may depend on how you are interacting with Python. (e.g. cpython, pyo3...)

I don't think the numpy C API exposes these types either, which is why there's nothing in the numpy crate. (And honestly I do think you need to have a pretty esoteric use case if you truly need one of these types and a Python float or rust f64 won't do!)

Ok how do I write the code?

Don't be a Help Vampire. Nobody is going to write your code for you.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.