combinations

How to calculate ratios and normalized ratios in all possible combinations in R?

陌路散爱 提交于 2020-08-10 19:18:39
问题 I want to calculate normalised ratios and simple ratios in all possible combinations in R. This is the sample dataset df = structure(list(var_1 = c(0.035, 0.047, 0.004, 0.011, 0.01, 0.01, 0.024), var_2 = c(0.034, 0.047, 0.004, 0.012, 0.01, 0.011, 0.025 ), var_3 = c(0.034, 0.047, 0.006, 0.013, 0.011, 0.013, 0.026), var_4 = c(0.034, 0.046, 0.008, 0.016, 0.014, 0.015, 0.028 ), var_5 = c(0.034, 0.046, 0.009, 0.017, 0.015, 0.016, 0.029 )), class = "data.frame", row.names = c(NA, -7L)) I could able

numba-safe version of itertools.combinations?

谁说胖子不能爱 提交于 2020-08-03 03:18:06
问题 I have some code which loops through a large set of itertools.combinations , which is now a performance bottleneck. I'm trying to turn to numba 's @jit(nopython=True) to speed it up, but I'm running into some issues. First, it seems numba can't handle itertools.combinations itself, per this small example: import itertools import numpy as np from numba import jit arr = [1, 2, 3] c = 2 @jit(nopython=True) def using_it(arr, c): return itertools.combinations(arr, c) for i in using_it(arr, c):

How to calculate normalized ratios in all possible combinations efficiently for a large matrix in R?

有些话、适合烂在心里 提交于 2020-07-22 05:51:05
问题 I want to calculate normalised ratios in all possible combinations efficiently for a large matrix in R. I have asked a similar question earlier here and with a small data and the solutions provided there worked fine. But when I am trying to apply the same solution for a large dataset (400 x 2151), my system is getting hang. My system is having 16 GB RAM with Intel i7 processer. Here is the code with data df <- matrix(rexp(860400), nrow = 400, ncol = 2151) Solution provided by @Ronak Shah cols

Listing all possible combination without repetition,VBA

泪湿孤枕 提交于 2020-07-22 04:35:49
问题 I have a code that work right now and lists numbers at 6 lenght.But they are repetive.But these numbers are repeated.I need unique non-repeated 6 digit. I have this kind of results right now.1 1 1 3 4 6 but i need different and non repeating results.Thank you for helping me. Sub AllCombinations() Dim nums(): nums = Array(1, 2, 3, 4, 5, 6, 7, 8, 9) Dim arValues(999999, 5) Dim n1 As Integer, n2 As Integer, n3 As Integer, n4 As Integer, n5 As Integer, n6 As Integer, x As Long For n1 = 0 To

Combinations with repetition in python, where order MATTERS

我与影子孤独终老i 提交于 2020-07-19 06:54:04
问题 From python's Documentation: https://docs.python.org/2/library/itertools.html#itertools.combinations see combinations_with_replacement: "# combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC" I'd like to use the same function, with the bonus of generating "BA", "CA", and "CB". 回答1: itertools.product is definitely the method you're looking for here. As the documentation states, it is effectively a compact for loop; product(A,B) is equivalent to ((x, y) for x in A for y in B) product

Python: breaking a list into all possible sublists

爷,独闯天下 提交于 2020-06-26 05:59:25
问题 Lets assume I've got a list of integers: mylist = [101, 102, 103, 104, 105, 106] Now I need to create every possible sublist division (order preserved): sublists = [([101], [102, 103, 104, 105, 106]), ([101, 102], [103, 104, 105, 106]), ([101, 102, 103], [104, 105, 106]), ... ([101, 102], [103, 104], [105, 106]), ... ([101], [102, 103, 104], [105], [106]), ... ([101], [102], [103], [104], [105], [106])] Any idea? Would itertools be helpful? 回答1: You are creating slice points ; are you slicing

Testing all combinations in Python

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-25 03:40:42
问题 I have two sets of options: optionList1 = [a1,a2,a3,...,an] optionList2 = [b1,b2,b3,...,bn] The number of elements in the optionlists are not necessarily equal and I have to choose from the first optionlist twice. How do I ensure that I have tried every combination of 2 options from the first list and one from the second list. An example selection set below... selectedOptions = [an1,an2,bn] 回答1: Assuming you don't want duplicate entries from list1, here's a generator that you can use to

Testing all combinations in Python

断了今生、忘了曾经 提交于 2020-06-25 03:40:00
问题 I have two sets of options: optionList1 = [a1,a2,a3,...,an] optionList2 = [b1,b2,b3,...,bn] The number of elements in the optionlists are not necessarily equal and I have to choose from the first optionlist twice. How do I ensure that I have tried every combination of 2 options from the first list and one from the second list. An example selection set below... selectedOptions = [an1,an2,bn] 回答1: Assuming you don't want duplicate entries from list1, here's a generator that you can use to

R - All pairwise combinations of column strings concatenated by the row

亡梦爱人 提交于 2020-06-16 04:05:31
问题 How can I transform data frames like this one: X__1 X__2 X__3 <chr> <chr> <chr> 1 a b c 2 d e f 3 g h i 4 j k l Into this one: X__1 X__2 X__3 <chr> <chr> <chr> 1 a-d b-e c-f 2 a-g b-h c-i 3 a-j b-k c-l 4 d-g e-h f-i 5 d-j e-k f-l 6 g-j h-k i-l In other words, it should make all possible pairwise combinations of the whole rows in the data frame, combining strings from the same column but separated by a sign(-). It does not need to repeat an already made combination in the other order of

How to get the combination of array values from nested arrays in an array of objects

天涯浪子 提交于 2020-05-23 09:21:13
问题 I have an array of objects with the following structure: var varientSections = [ { type: "frame", values: ["black", "white", "wood"] }, { type: "finish", values: ["matte", "glossy"] } ]; I want to get the combination of the array values and create a new list with it. Right now, I am able to retrieve the combination from the nested array values using the method called getCombination(varientSections) . However, I do not know how to create a new list with the following structure: var results = [