建设蟒蛇numpy的的N×N矩阵,为任意n [英] building an nxn matrix in python numpy, for any n

查看:233
本文介绍了建设蟒蛇numpy的的N×N矩阵,为任意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 nxn 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆