如何使用sapply函数清理此代码?
Orig <- .45
Adjusted <- matrix(1:130, nrow =13)
Original <- rbind(Orig,
Orig1 <- pmin(Orig*(1+Adjusted[1,]),100),
Orig2 <- pmin(Orig1*(1+Adjusted[2,]),100),
Orig3 <- pmin(Orig2*(1+Adjusted[3,]),100),
Orig4 <- pmin(Orig3*(1+Adjusted[4,]),100),
Orig5 <- pmin(Orig4*(1+Adjusted[5,]),100),
Orig6 <- pmin(Orig5*(1+Adjusted[6,]),100),
Orig7 <- pmin(Orig6*(1+Adjusted[7,]),100),
Orig8 <- pmin(Orig7*(1+Adjusted[8,]),100),
Orig9 <- pmin(Orig8*(1+Adjusted[9,]),100),
Orig10 <- pmin(Orig9*(1+Adjusted[10,]),100),
Orig11 <- pmin(Orig10*(1+Adjusted[11,]),100),
Orig12 <- pmin(Orig11*(1+Adjusted[12,]),100)
)
Run Code Online (Sandbox Code Playgroud) 我需要创建一些处理任意大小矩阵的函数.我熟悉这里使用的declare语法,但这是为了大学任务,我的教授告诉我,使用'declare'有一些矫枉过正.我在网上找不到任何相关内容,有什么帮助吗?
基本上我想通过键盘获得矩阵大小,然后使用生成的矩阵,我坚持declare
目前我有:
type myMatrix is array (Natural range <>, Natural range <>) of Integer;
type myVector is array (Natural range <>) of Integer;
Run Code Online (Sandbox Code Playgroud)
我用它作为:
procedure Lab1 is
begin
declare A, B: myVector(1..5):=
(3, 14, 15, 92, 6);
Run Code Online (Sandbox Code Playgroud)
它不允许在运行时指定大小,并且:
declare
int1:Integer:=generate_random_number(50)+2;
int3:Integer:=generate_random_number(50)+2; -- +2 so we don't get length/size 0 or 1
X, Y:myVector(1..int1):=(others=>generate_random_number(20));
MT:myMatrix(1..int1, 1..int3):=(others =>(others=>generate_random_number(10))); -- 'others' used for all the unmentioned elements, http://rosettacode.org/wiki/Array_Initialization
MS:myMatrix(1..int3, 1..int1):=(others =>(others=>generate_random_number(10)));
F3_result:myMatrix(1..int1, 1..int1);
begin
F3_result:=F3(X, Y, MT, …Run Code Online (Sandbox Code Playgroud) 假设我有2个变量的函数,F(i,j)这取决于矩阵的行索引和列索引,我想用值填充矩阵M_ij = F(i,j)
当然,这是有可能通过做一个循环i和j,甚至只有i或者j如果函数F可以向量化,但我想知道整洁的方式做到这一点.
我有一个类使用颜色矩阵在ImageView上添加图像效果.我有几种颜色矩阵用于对比度,曝光,温度和饱和度.例如:
public static Bitmap changeContrast(Bitmap bmp, float contrast)
{
ColorMatrix cm = new ColorMatrix(new float[]
{
contrast, 0, 0, 0, 0,
0, contrast, 0, 0, 0,
0, 0, contrast, 0, 0,
0, 0, 0, 1, 0
});
return getBitmapFromColorMatrix(cm, bmp);
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,图像的锐化.这些似乎没有颜色矩阵.请帮忙.
我尝试使用此处的代码锐化图像,但处理时间太长,我不知道应该将哪些有效值传递给方法的权重参数sharpenImage(Bitmap src, double weight) .
我有一个矩阵(大约342乘342)表示C_{ij},我想根据条件识别原始的矩形子矩阵C_{ij}.我正在使用MATLAB
例如,如果我有矩阵C_{ij}:
C = 1 0.7 0.8
0.7 1 0.5
0.8 0.5 1
Run Code Online (Sandbox Code Playgroud)
并且rho = 0.6然后我希望我的代码识别的正确的方形子矩阵是:
C = 1 0.7 0.8
0.7 1 0.5
0.8 0.5 1
Run Code Online (Sandbox Code Playgroud)
我不确定如何/最好的方法是在MATLAB中做到这一点?虽然我现在使用的矩阵是对称的,但我更倾向于一种不假设的解决方案.
如何找到矩阵给定行中最大的所有索引.max(a(1,:))仅返回第一个最大值!
我想要所有最大元素的索引(多个)
我想知道如何创建具有随机自然数但每列总和等于每行总和对角线总和的矩阵。
我的意思是,您创建了一个函数,该函数通过选择行,列和对角线的尺寸和总和为您提供一个如上所述的方阵,但是每行和每列的数字不同。
有人知道如何做到这一点吗?
我想自己创建一个没有任何程序包的功能,以完全理解该程序。
我有一个非唯一值的矩阵(或多维数组),如下所示:
var matrix = [
[1, 3, 2, 4, 1],
[2, 4, 1, 3, 2],
[4, 3, 2, 1, 4]
]
Run Code Online (Sandbox Code Playgroud)
我想对这个矩阵的一行进行排序,但是其他行应该重新排序,以保持列像组织一样.
//matrix sorted by the row 0
var sorted_matrix = [
[1, 1, 2, 3, 4],
[2, 2, 1, 4, 3],
[4, 4, 2, 3, 1]
]
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我更喜欢lodash解决方案.
我有一个Java方法fill0s(),它将一个较小的矩阵输入到一个较大的矩阵中,据说填充了0:
public class PoolingFunctions {
// Fill needed spaces with 0
public static Double[][] fill0s(Double[][] image, int filter_size){
int columns_remaining = filter_size - (image[0].length%filter_size);
int rows_remaining = filter_size - (image.length%filter_size);
// CREATE A MATRIX: HERE LIES THE PROBLEM: //////////////////////////////
Double [][] blank_matrix = new Double [(image.length)+columns_remaining][(image[0].length)+rows_remaining];
for (int i = 0; i<image.length; i++) {
for (int j = 0; j<image[i].length; j++) {
blank_matrix[i][j] = image[i][j];
}
}
return blank_matrix;
}
}
Run Code Online (Sandbox Code Playgroud)
并在调用此方法后:
public class MainPooling{
public static void …Run Code Online (Sandbox Code Playgroud) 对于下面的数组,我有兴趣根据y轴对X轴进行排序,并记录最低X值的最低元组.
该数组是:
A = [(537, 14),
(537, 12),
(538, 13),
(538, 14), # (538, 14) should be removed and (537, 14) should be kept
(539, 12),
(709, 9)]
Run Code Online (Sandbox Code Playgroud)
我会这样做:
New_A = [(537, 14),
(537, 12),
(538, 13),
(539, 12),
(709, 9)]
Run Code Online (Sandbox Code Playgroud)
我可以在这尝试什么?
matrix ×10
matlab ×3
arrays ×2
r ×2
sorting ×2
ada ×1
android ×1
colormatrix ×1
convolution ×1
coordinates ×1
function ×1
java ×1
javascript ×1
lodash ×1
magic-square ×1
max ×1
null ×1
python ×1
rbind ×1
threshold ×1