我正在尝试在导航抽屉项目中实现切换按钮,Android Studio可以自动生成.最后我想要这样的东西("仅下载"-Button):
不幸的是,我不明白如何将切换按钮添加到NavDrawer的ListView.我可能会使用其中一个"Custom NavDrawer Libs",但我想了解Google使用自动生成的示例提出的方式.
有关如何将其实现到默认NavDrawer项目的任何想法?
我的程序生成以下列表(摘录):
my_list = [{'x': 1764, 'y': 18320, 'class': 'note', 'id': 'd1e2443'},
{'x': 1764, 'y': 20030, 'class': 'note', 'id': 'd1e2591'},
{'x': 1807, 'y': 12650, 'class': 'note', 'id': 'd1e1362'},
{'x': 2243, 'y': 20120, 'class': 'note', 'id': 'd1e2609'},
{'x': 2243, 'y': 22685, 'class': 'note', 'id': 'd1e2769'},
{'x': 2257, 'y': 12560, 'class': 'note', 'id': 'd1e1380'},
{'x': 2688, 'y': 20210, 'class': 'note', 'id': 'd1e2625'},
{'x': 2707, 'y': 10040, 'class': 'note', 'id': 'd1e1194'},
{'x': 2707, 'y': 12650, 'class': 'note', 'id': 'd1e1398'},
{'x': 2707, 'y': 14720, 'class': …Run Code Online (Sandbox Code Playgroud) 我有一个 numpy 数组,其维度为12 x 12 x 4。现在我试图向这个立方体添加一个额外的层,从而形成一个12 x 13 x 4数组。第 13 层应包含来自第一个轴的相应索引,因此例如寻址[7, 13, :]结果为[7, 7, 7, 7]。
很难解释,但也许有人对如何使用 numpy 实现这一目标有一些建议?
编辑:我找到了一个解决方案,尽管它看起来有点过于复杂:
# Generate extra layer
layer = np.repeat(np.arange(0, 12)[:, np.newaxis], data.shape[2], axis=1)
# Get dimensions right...
layer = np.expand_dims(layer, axis=1)
# ... and finally append to data
result = np.append(data, layer, axis=1)
Run Code Online (Sandbox Code Playgroud)
仍然欢迎更好的建议。
我想有一个矩阵ndarray作为其他模块可用的常量。不幸的是,构造函数本身并不是一个常数函数。有没有办法绕过这个限制?
代码:
extern crate ndarray;
use ndarray::prelude::*;
const foo: Array2<f32> = arr2(&[
[1.26, 0.09], [0.79, 0.92]
]);
fn main() {
println!("{}", foo);
}
Run Code Online (Sandbox Code Playgroud)
错误:
extern crate ndarray;
use ndarray::prelude::*;
const foo: Array2<f32> = arr2(&[
[1.26, 0.09], [0.79, 0.92]
]);
fn main() {
println!("{}", foo);
}
Run Code Online (Sandbox Code Playgroud)