-1

我正在尝试沿同一轴连接 3 个 1d 数组,以便它们构成一个长的 1d 数组。

use std::time::Instant;
// use std::error::Error;
// use std::fs::File;
// use std::io::Write;
// use std::process;
use ndarray::{Array, Axis, concatenate};


fn main() {
    let start = Instant::now();

    let speed_m_s_up = Array::<f64, _>::range(0.0, 20.0, 0.2);
    let speed_m_s_cruise = Array::<f64, _>::ones(3_000) * 20.0;
    let speed_m_s_down = Array::<f64, _>::range(19.8, -0.2, -0.2);

    let speed_m_s = concatenate(Axis(0), &[speed_m_s_up.view(), speed_m_s_cruise.view(), speed_m_s_down.view()]);
    // let time_s = Array::<f64, _>::range(0.0, speed_m_s. as f64, 1.0);

    let duration = start.elapsed();
    println!("Elapsed time: {:?}", duration);
    println!("{:?}", speed_m_s.len());
}

导致错误:

error[E0599]: no method named `len` found for enum `Result` in the current scope
  --> src/main.rs:21:32
   |
21 |     println!("{:?}", speed_m_s.len());
   |                                ^^^ method not found in `Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ShapeError>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `testaroo` due to previous error

如何将其更改speed_m_s为一维数组?

4

0 回答 0