建设蟒蛇numpy的的N×N矩阵,为任意n [英] building an nxn matrix in python numpy, for any n
问题描述
时有可能使用的Python(3.3版本)numpy的写code构建的N×N矩阵,而无需指定N'我需要索引条目A_I,J或类似的东西,但我甚至不知道如何界定A_I,J,使他们实际上是对象。我觉得这样的事情可能工作:
Is it possible using numpy for python (versions 3.3) to write the code for building an nxn matrix, without specifying n? I need to index the entries as A_i,j or something like that, but I dont even know how to define the A_i,j so that they are actually objects. I thought something like this might work:
n
i=1
j=1
when i (is less than) n+1
when j (is less than) i+1
A_i,j= f(i,j)
j+=1
i+=1
但是,这并不工作...有什么建议?
我的最终目标是编写一个任意n×n的矩阵QR分解。但我需要知道如何定义,我第一次工作的矩阵。我很新的蟒蛇,因此numpy的,因此不知道任何东西。任何帮助将大大AP preciated。我也是新stackexchange很抱歉的坏块code我已经在那里。 (小于)被假定为是指三角形符号失踪头指向比符号明显少左基部
but this does not work...any suggestions? My ultimate Goal is to write the QR decomposition for an arbitrary nxn matrix. But I need to know how to define the matrix that I am working on first. I am very new to python and thus numpy and so dont know much of anything. any help would be greatly appreciated. I am also new to stackexchange so sorry for the bad piece of code i have there. (is less than) is supposed to mean the triangle sign missing the base with head pointing to the left- that is the obvious less than symbol
推荐答案
您可以创建一个空 N
X N
数组:
You can create an empty n
xn
array:
import itertools
import numpy as np
my_array = np.empty([n, n])
然后,在协调 I,J
到 F(I,J)所设置的值
。
for i, j in itertools.product(range(n), range(n)):
my_array[i, j] = f(i, j)
这篇关于建设蟒蛇numpy的的N×N矩阵,为任意n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!