程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

R expand in Python Grid() function - R expand grid() function in Python

編輯:Python

problem :

Is there a Python function similar to the expand.grid() function in R ? Is there anything similar to R Medium expand.grid() Functional Python function ?Thanks in advance. Thank you in advance .

(EDIT) Below are the description of this R function and an example.( edit ) Here's this R Function description and an example .

Create a Data Frame from All Combinations of FactorsDescription: Create a data frame from all combinations of the supplied vectors or factors. > x <- 1:3> y <- 1:3> expand.grid(x,y) Var1 Var21 1 12 2 13 3 14 1 25 2 26 3 27 1 38 2 39 3 3

(EDIT2) Below is an example with the rpy package.(EDIT2) Here is a belt with rpy An example of a package .I would like to get the same output object but without using R : I want to get the same output object but don't use R :

>>> from rpy import *>>> a = [1,2,3]>>> b = [5,7,9]>>> r.assign("a",a)[1, 2, 3]>>> r.assign("b",b)[5, 7, 9]>>> r("expand.grid(a,b)"){'Var1': [1, 2, 3, 1, 2, 3, 1, 2, 3], 'Var2': [5, 5, 5, 7, 7, 7, 9, 9, 9]}

EDIT 02/09/2012: I'm really lost with Python. edit 02/09/2012: I'm really lost Python.Lev Levitsky's code given in his answer does not work for me:Lev Levitsky The code given in his answer doesn't work for me :

>>> a = [1,2,3]>>> b = [5,7,9]>>> expandgrid(a, b)Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in expandgridNameError: global name 'itertools' is not defined

However the itertools module seems to be installed (typing from itertools import * does not return any error message) But it seems that itertools modular ( from itertools import * Input will not return any error messages )


Solution :

Reference resources : https://stackoom.com/en/question/otnP

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved