小编dod*_*she的帖子

创建一个"金字塔"矩阵

假设我给出了一个奇数长度的对称行向量,其中每个元素小于向量的前半部分中的下一个元素,并且每个元素大于下半部分中的下一个元素,中间元素是最大的.(例如[1 2 3 2 1][10 20 50 20 10]).

我想创建一个方形矩阵,其中此行向量是其中间行,等效列vector(v')是其中间列,并且每个其他行或列是给定向量的缩减版本,根据此行或列中的中间元素.当我们没有更多的"原始元素"时0.

例子:

如果v = [1 2 3 2 1]我们得到

0 0 1 0 0  
0 1 2 1 0  
1 2 3 2 1  
0 1 2 1 0  
0 0 1 0 0
Run Code Online (Sandbox Code Playgroud)

如果v = [3 5 3]我们得到

0 3 0  
3 5 3  
0 3 0  
Run Code Online (Sandbox Code Playgroud)

到目前为止我做了什么:我设法创建了一个矩阵v作为中间行和v'中间列,我写了这个代码:

s = length(vector);
matrix= zeros(s);
matrix(round(s/2),:) …
Run Code Online (Sandbox Code Playgroud)

arrays matlab matrix

12
推荐指数
3
解决办法
1754
查看次数

NestJS + Mongoose 模式与自定义打字稿类型

nestjs/mongoose我正在尝试使用以下类中的装饰器创建 Mongo 模式:

@Schema()
export class Constraint {
  @Prop()
  reason: string;

  @Prop()
  status: Status;

  @Prop()
  time: number;
}

Run Code Online (Sandbox Code Playgroud)

问题Status定义如下:

export type Status = boolean | 'pending';

Run Code Online (Sandbox Code Playgroud)

我无法弄清楚要传递给status'sprop装饰器的内容,因为我收到以下错误:

Error: Cannot determine a type for the "Constraint.status" field (union/intersection/ambiguous type was used). Make sure your property is decorated with a "@Prop({ type: TYPE_HERE })" decorator
Run Code Online (Sandbox Code Playgroud)

并且{ type: Status }不起作用,因为Status是 atype而不是 a Class

mongoose mongodb typescript mongoose-schema nestjs

6
推荐指数
1
解决办法
1514
查看次数