精华内容
下载资源
问答
  • MATLAB permute命令的操作逻辑

    千次阅读 多人点赞 2019-12-20 11:32:30
    MATLAB中permute命令可以对高维矩阵的轴进行操作,例如使2*3*4的三维矩阵调整为4*2*3,那么具体函数内部进行了什么操作呢? 我们知道matlab里有两种坐标系,一种是我们熟知的笛卡尔坐标系,用命令axis xy实现,以二...

    MATLAB中permute命令可以对高维矩阵的轴进行操作,例如使2*3*4的三维矩阵调整为4*2*3,那么具体函数内部进行了什么操作呢?

    我们知道matlab里有两种坐标系,一种是我们熟知的笛卡尔坐标系,用命令axis xy实现,以二维图为例,原点在左下角

    还有一种是matlab中矩阵的索引体系,用命令axis ij实现,以二维图为例,原点在左上角

    permute命令就是基于axis ij这种坐标轴下进行的操作

    下面我们以一个三维矩阵的例子来说明命令permute的内部操作逻辑

    A(:,:,1)=[1 2;3 4];
    A(:,:,2)=[5 6;7 8];
    A(:,:,3)=[9 10; 11 12];
    我们有
    
    val(:,:,1) =
    
         1     2
         3     4
    
    
    val(:,:,2) =
    
         5     6
         7     8
    
    
    val(:,:,3) =
    
         9    10
        11    12
    
    

    permute(a,order)操作分为两种情况

    1.保持坐标轴关系不变

    也就是order=[2 3 1]或[3 1 2]

    这时候只用找到一个角度来重新观察这个矩阵即可

    例如下图中所示

    用MATLAB运行结果进行验证

    D=permute(A,[2 3 1]);
    
    val(:,:,1) =
    
         1     5     9
         2     6    10
    
    
    val(:,:,2) =
    
         3     7    11
         4     8    12
    
    

    2,某两个轴进行交换

    例如order = [1 3 2] [2 1 3] [3 2 1]

    那么就是针对这两个轴的数据进行转置,如上图所示

    用MATLAB运行结果进行验证

    B=permute(A,[2 1 3]);
    
    val(:,:,1) =
    
         1     3
         2     4
    
    
    val(:,:,2) =
    
         5     7
         6     8
    
    
    val(:,:,3) =
    
         9    11
        10    12
    
    

     

    展开全文
  • MATLAB中permute的运用

    千次阅读 2015-06-13 16:04:27
    permute:Rearrange dimensions of N-D array Syntax:B = permute(A,order) ...Description:B = permute(A,order) rearrangesthe dimensions of A so that they are in the orderspecified by the vector order. B


    permute:Rearrange dimensions of N-D array


    Syntax:B = permute(A,order)

    Description:B = permute(A,order) rearrangesthe dimensions of A so that they are in the orderspecified by the vector order. B hasthe same values of A but the order of the subscriptsneeded to access any particular element is rearranged as specifiedby order. All the elements of order mustbe unique, real, positive, integer values.






    Examples


    Given any matrix A, the statement
    permute(A,[2 1]) 


    is the same as A.'.


    For example:
    A = [1 2; 3 4]; permute(A,[2 1])
    ans =
         1     3
         2     4


    The following code permutes a three-dimensional array:
    X = rand(12,13,14);
    Y = permute(X,[2 3 1]);
    size(Y)
    ans =
        13    14    12
    展开全文
  • Permute Digits

    2018-01-26 17:54:34
    D - Permute Digits You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can sta

    D - Permute Digits
    You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.

    It is allowed to leave a as it is.

    Input
    The first line contains integer a (1 ≤ a ≤ 1018). The second line contains integer b (1 ≤ b ≤ 1018). Numbers don’t have leading zeroes. It is guaranteed that answer exists.

    Output
    Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can’t have any leading zeroes. It is guaranteed that the answer exists.

    The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.

    Example
    Input
    123
    222
    Output
    213
    Input
    3921
    10000
    Output
    9321
    Input
    4940
    5000
    Output
    4940

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int k = 0;
    int main(){
        char a[20],b[20];
        int ans[20],cnt[10],flag,flag1;
        memset(cnt,0,sizeof(cnt));
        flag = -2;
        flag1 = 0;
        cin>>a>>b;
        for(int i = 0;i < strlen(a);i++)
            cnt[a[i]-'0']++;
        ///位数比b小,直接逆序输出 
        if(strlen(a)<strlen(b)){
            for(int i = 9;i>=0;i--){
                while(cnt[i]-- != 0) ans[k++] = i;
            }
        }
        ///位数相等的时候 
        else{
            while(k<strlen(a)){
                ///判断是否需要回溯 
                if(flag == 1){
                    k--;
                    cnt[ans[k]]++;
                    for(int i = b[k]-'0'-1;i>=0;i--){
                        if(cnt[i]!=0){
                            ans[k] = i;
                            cnt[i]--;
                            flag = -1;
                            break;
                        }
                    }
                    ///如果回溯,此时一定比b该位的数小,后面直接逆序输出 
                    if(flag == -1) break;
                    if(flag == 1) continue;         
                }
                ///如果i位和b该位相等继续循环 
                if(cnt[b[k]-'0']!=0){
                    cnt[b[k]-'0']--;
                    ans[k] = b[k]-'0';
                }
                ///如果i位比b该位小,打破循环,后面逆序输出 
                else{
                    flag1 = 0;
                    for(int i = (b[k]-'0')-1;i>=0;i--){
                        if(cnt[i]!=0){
                            ans[k] = i;
                            cnt[i]--;
                            flag1 = flag = -1;
                            break;
                        }
                    }
                    if(flag1 != -1) flag = 1;
                }
                if(flag == -1) break;
                if(flag==1) continue;
                k++;
            }
    
        }
        ///中途跳出来循环 剩下的逆序输出 
        if(flag == -1){
            for(int i = 9;i >= 0;i--)
                while(cnt[i]!=0){
                    ans[++k] = i;
                    cnt[i]--;   
                }
            for(int i = 0;i < strlen(a);i++)
                cout<<ans[i];
                cout<<endl; 
        }
        ///中途为打破循环 等于b或者位数比b小 
        else{
            for(int i = 0;i < strlen(a);i++)
                cout<<ans[i];
                cout<<endl; 
        }
        return 0;
    }

    代码方法:计数a中0-9出现个数,然后从第一位开始找,如果有和b改为相等的数,继续循环,如果没有,找比b该位小的数(如果没有比b该位小的数,回溯上一位找比b小的数)。注意其中的flag的值变化。
    修改过程中卡死的好久的一个特例:1230 1300

    展开全文
  • permute

    2019-04-27 22:29:00
    格式: B = repmat(A, m, n) %将矩阵A复制m*n块,即B由m*n块A平铺而成 B = repmat(A, [m n])%与上面一致 B = repmat(A, [m n p...]) %B由m*n*p*...个A块平铺而成 repmat(A, m, n) %当A是一个数a时,该命令产生一...
    repmat函数用法
    复制和平铺矩阵
     
    函数repmat
    格式:  B = repmat(A, m, n) %将矩阵A复制m*n块,即B由m*n块A平铺而成
    B = repmat(A, [m n])%与上面一致
    B = repmat(A, [m n p...]) %B由m*n*p*...个A块平铺而成
    repmat(A, m, n) %当A是一个数a时,该命令产生一个全由a组成的m*n矩阵
     
    permute函数用法
    对N维数组重新排列其维数
     
    使用方法:
    B = permute(A,order)
    对N维数组A按照指定的向量order顺序来重新排列其维数,B和A有相同的值但是任何需要访问的特定元素其下标的顺序是被指定的向量order顺序来重新排列的,向量order中的元素必须是唯一的。
    应用举例:
    给定任一矩阵A,表达式:
    permute(A,[2 1]) 和A.'相同的。
    比如:
    A = [1 2; 3 4]
    A =
     
    1 2
    3 4
    permute(A,[2 1])
    ans =
    1 3
    2 4
    下面的代码排列三维数组:
    X = rand(12,13,14);
    Y = permute(X,[2 3 1]);
    size(Y)
    ans =
    13 14 12

    转载于:https://www.cnblogs.com/hyb221512/p/10780805.html

    展开全文
  • Permute Digitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two positive integer numbers a and b. Permute (change order) of the...
  • You are given two positive integer numbers a and... Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.I...
  • C. Permute Digits time limit per test1 second memory limit per test256 megabytes You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal n
  • Matlab中repmat、permute函数用法

    万次阅读 2018-01-16 21:36:13
    格式: B = repmat(A, m, n) %将矩阵A复制m*n块,即B由m*n块A平铺而成 B = repmat(A, [m n])%与上面一致 B = repmat(A, [m n p...]) %B由m*n*p*...个A块平铺而成 repmat(A, m, n) %当A是一个数a时,该命令产生一...
  • C. Permute Digits

    2018-01-16 22:33:09
    C. Permute Digitstime limit per test 1 second memory limit per test 256 megabytes input standard input ...standard outputYou are given two positive integer numbers a and b. Permute (change o
  • G - Permute Digits

    2018-01-22 20:24:52
    You are given two positive integer numbers a and ... Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit
  • 题目链接:... C. Permute Digits You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not ex...
  • Permute Digits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two positive integer numbers
  • Description You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with
  • 1/26 训练五 深度优先搜索(dfs) E .(dfs 减枝! 注意回溯!给两个数ab,输出不超过b的最大a的重排) Permute Digits ... Permute (change order) of the digits of a to construct maximal numbe
  • cf Permute Digits(dfs)

    2018-08-21 15:29:00
    C. Permute Digits You are given two positive integer numbersaandb. Permute (change order) of the digits ofato construct maximal number not exceedingb. No number in input and/or output can sta...
  • You are given two positive integer numbersaandb. Permute (change order) of the digits ofato construct maximal number not exceedingb. No number in input and/or output can start with the digit0. ...
  • There are many SO questions related to arg/opt order, but none seem answer this question: Can argparse be made to permute argument order like getopt? The use case is a prototypical command line ...
  • Permute Digits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two positive integer numbers
  • B = permute(A,order) 按照向量order指定的顺序重排A的各维  train_X = permute(pooledFeaturesTrain, [1 3 4 2]);  % 将每个样本的特征拉成一个列向量,每个样本一个列,矩阵大小为3600*2000  ...
  • Description You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with
  • You are given two positive integer numbersaandb. Permute (change order) of the digits ofato construct maximal number not exceedingb. No number in input and/or output can start with the digit0. ...
  • Permute Digits 915C

    2018-08-11 19:14:00
    You are given two positive integer numbersaandb. Permute (change order) of the digits ofato construct maximal number not exceedingb. No number in input and/or output can start with the digi...
  • 915C Permute Digits

    2018-01-14 20:14:40
    Permute Digits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two positive integer numbers
  • Permute Digits time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two positive integer numbersaandb...
  • y-a-b-e

    2016-10-20 14:57:04
    算法 ...【LC总结】翻转链表 Swap in Pairs, Reverse in k-Group, Reverse LinkedList###Reverse a doubly linkedlist reverse singly linked list Iteration: public ListNode reverseList(Lis...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,328
精华内容 531
关键字:

b=permute(a,order)