“Rust ndarray”的版本间的差异

来自wrc's Wiki
跳到导航 跳到搜索
(建立内容为“ndarray 是 Rust 的一个类似 Python numpy 的一个库。 == 笔记 == === [https://docs.rs/ndarray-stats/*/ndarray_stats/histogram/index.html histogram…”的新页面)
 
 
第27行: 第27行:
 
let hg = varr.histogram(grid);
 
let hg = varr.histogram(grid);
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== 参见 ==
 +
 +
* [https://docs.rs/ndarray ndarray 文档]
 +
* [https://github.com/rust-ndarray/ndarray ndarray 仓库]
 +
* [https://docs.rs/ndarray-stats ndarray-stats 文档]
  
 
[[Category:Rust|N]]
 
[[Category:Rust|N]]

2021年5月17日 (一) 23:22的最新版本

ndarray 是 Rust 的一个类似 Python numpy 的一个库。

笔记

histogram

use ndarray::Array;
use ndarray_stats::histogram::strategies::Auto;
use ndarray_stats::histogram::{GridBuilder, HistogramExt};

let vlist: Vec<usize> = ...;
// 转化数据为 Array
let varr = Array::from_shape_vec((vlist.len(), 1), vlist).unwrap();
// grid 为分割点,左闭右开
let grid = GridBuilder::<Auto<usize>>::from_array(&varr).unwrap().build();

其中 Auto<usize> 为一个 strategy

使用 grid:

// 20000 落在哪个区间?返回一个 std::ops::Range
// grid.projections() 是每个坐标轴对应的分割点
let r = grid.projections()[0].range_of(&20000).unwrap();
// 创建 histogram
let hg = varr.histogram(grid);

参见