Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 PARI/GP 中声明和调用数组?
例如,我在 java 中有以下内容:
int[] myArray = new int[5]; for(int i = 0; i < 5; i++){ myArray[i] = i + 5; }
使用 PARI/GP 时如何做同样的事情?
通常的方法是
myArray = vector(5, i, i+4);
因为 GP 向量是基于 1 的,而不是基于 0 的,所以我已将其替换i+5为。i+4
i+5
i+4
你也可以做
myArray = vector(5); for(i=1,5, myArray[i] = i+4);
如果你更喜欢。(这在某些情况下很有用,例如,当您想要引用数组中较早的值时。)
x = []; for (i=1,10, print("test " i ": " x[i]))