permute

Permutation and Combination in PhP

家住魔仙堡 提交于 2021-01-29 09:32:08
问题 I I want to compute the permutations 5p2, 5p3, 5p4 and 5p5 from the array [1,2,3,4,5] The function below only runs 5p5. To run 5p2, 5p3, 5p4 I will have to manually iterate through the array using a for...loop. Please help me. //function to return permutations 5p5 array function combinationArray($myarr) { $results = []; $current = []; $next = function($myarr) use(&$next,&$results,&$current) { $l = count($myarr); if($l === 1) { $current []= $myarr[0]; $results []= intval(implode($current)); /

How to calculate permutations of group labels with R?

落爺英雄遲暮 提交于 2021-01-27 19:22:29
问题 Given a vector like: labels <- c(1,2,3,3,3) How to get all possible group relabelings? For this example: 1,2,3,3,3 1,3,2,2,2 2,1,3,3,3 2,3,1,1,1 3,1,2,2,2 3,2,1,1,1 I have been looking at the permute package but I don't see how to apply it to this case. 回答1: How about this solution labels <- c(1,2,3,3,3) library(data.table) a <- do.call(cbind, combinat::permn(unique(labels))) data.table(a)[,lapply(.SD, function(x)x[labels]),] # V1 V2 V3 V4 V5 V6 #1: 1 1 3 3 2 2 #2: 2 3 1 2 3 1 #3: 3 2 2 1 1 3

Get the combination of 2 lists

狂风中的少年 提交于 2020-06-01 02:22:45
问题 I'm reposting this question because I was told that there is a solution for that in the last post. I have 2 lists: list1 = ["foo", "bar", "lorem"] list2 = ["X", "Y"] I want to have the possible combinations from these 2 lists, meaning: [["foo", "bar", "lorem"], ["foo", "bar", "loremX"], ["foo", "barX", "loremX"], ["fooX", "bar", "loremX"], ["fooX", "barX", "loremX"], ["foo", "barX", "lorem"], ["fooX", "barX", "lorem"], ["fooX", "bar", "lorem"], ["foo", "bar", "lorem"], ["foo", "bar", "loremY"

Get the combination of 2 lists

限于喜欢 提交于 2020-06-01 02:20:30
问题 I'm reposting this question because I was told that there is a solution for that in the last post. I have 2 lists: list1 = ["foo", "bar", "lorem"] list2 = ["X", "Y"] I want to have the possible combinations from these 2 lists, meaning: [["foo", "bar", "lorem"], ["foo", "bar", "loremX"], ["foo", "barX", "loremX"], ["fooX", "bar", "loremX"], ["fooX", "barX", "loremX"], ["foo", "barX", "lorem"], ["fooX", "barX", "lorem"], ["fooX", "bar", "lorem"], ["foo", "bar", "lorem"], ["foo", "bar", "loremY"

Get the combination of 2 lists

寵の児 提交于 2020-06-01 02:14:13
问题 I'm reposting this question because I was told that there is a solution for that in the last post. I have 2 lists: list1 = ["foo", "bar", "lorem"] list2 = ["X", "Y"] I want to have the possible combinations from these 2 lists, meaning: [["foo", "bar", "lorem"], ["foo", "bar", "loremX"], ["foo", "barX", "loremX"], ["fooX", "bar", "loremX"], ["fooX", "barX", "loremX"], ["foo", "barX", "lorem"], ["fooX", "barX", "lorem"], ["fooX", "bar", "lorem"], ["foo", "bar", "lorem"], ["foo", "bar", "loremY"

Permutations of 3 elements within 6 positions

夙愿已清 提交于 2019-12-23 14:54:14
问题 I'm looking to permute (or combine) c("a","b","c") within six positions under the condition to have always sequences with alternate elements, e.g abcbab . Permutations could easily get with: abc<-c("a","b","c") permutations(n=3,r=6,v=abc,repeats.allowed=T) I think is not possible to do that with gtools, and I've been trying to design a function for that -even though I think it may already exist. 回答1: Since you're looking for permutations, expand.grid can work as well as permutations . But

Permutations of 3 elements within 6 positions

馋奶兔 提交于 2019-12-23 14:54:01
问题 I'm looking to permute (or combine) c("a","b","c") within six positions under the condition to have always sequences with alternate elements, e.g abcbab . Permutations could easily get with: abc<-c("a","b","c") permutations(n=3,r=6,v=abc,repeats.allowed=T) I think is not possible to do that with gtools, and I've been trying to design a function for that -even though I think it may already exist. 回答1: Since you're looking for permutations, expand.grid can work as well as permutations . But

How do I swap tensor's axes in TensorFlow?

荒凉一梦 提交于 2019-12-17 18:17:23
问题 I have a tensor of shape (30, 116, 10) , and I want to swap the first two dimensions, so that I have a tensor of shape (116, 30, 10) I saw that numpy as such a function implemented ( np.swapaxes ) and I searched for something similar in tensorflow but I found nothing. Do you have any idea? 回答1: tf.transpose provides the same functionality as np.swapaxes , although in a more generalized form. In your case, you can do tf.transpose(orig_tensor, [1, 0, 2]) which would be equivalent to np.swapaxes

JULIA : How to permute randomly a vector in julia?

好久不见. 提交于 2019-12-11 01:57:49
问题 l have a vector of random numbers that l want to permute randomly using randperm() function as follows but it's not working. X=rand(100000) # a vector of 100000 random elements Y=randperm(X) # want to permute randomly the vector x the returned error is : ERROR: MethodError: no method matching randperm(::Array{Float64,1}) in eval(::Module, ::Any) at ./boot.jl:237 Thank you 回答1: Based on the docs the randperm() accepts an integer n and gives a permutation of length n. You can use this ordering

How do I swap tensor's axes in TensorFlow?

孤者浪人 提交于 2019-11-28 06:53:59
I have a tensor of shape (30, 116, 10) , and I want to swap the first two dimensions, so that I have a tensor of shape (116, 30, 10) I saw that numpy as such a function implemented ( np.swapaxes ) and I searched for something similar in tensorflow but I found nothing. Do you have any idea? keveman tf.transpose provides the same functionality as np.swapaxes , although in a more generalized form. In your case, you can do tf.transpose(orig_tensor, [1, 0, 2]) which would be equivalent to np.swapaxes(orig_np_array, 0, 1) . 来源: https://stackoverflow.com/questions/38212205/how-do-i-swap-tensors-axes