Reputation: 715
I am trying to store as a variable in a python script, mxn
arrays using nested loops as follows:
A=[ ]
for j in ListA:
for x in ListB:
values = some.function(label_fname, stc_fname)
A(j)=values(x)
for each x
, values
is an mxn
matrix with m~=n
.
When I index values here by values[x]
or values(x)
I get:
output operand requires a reduction, but reduction is not enabled
OR can't assign to function call
.
What I would like to due is append values(x)
matrices and store in A(j)
. Honestly, I can't say this in English, but in matlab lingo I am trying to create a cell array, where A{j}
is an mxn
array.
Thanks in advance.
Upvotes: 0
Views: 279
Reputation: 113955
You seem to have several issues with python:
When indexing into a list, use [
and ]
; not (
and )
. Also, the first element of a list is at index 0. This means that if you have a list `L = ['a', 'b', 'c', 'd'],
From what I understand from your explanation, I would suggest the following code. See if it works for you:
A = []
for sub_list in ListA:
temp = []
for x in ListB:
values = some.function(label_fname, stc_fname)
temp.append(values)
A.append(temp)
I'm really not very sure what you are asking for, but hopefully, this is a good start. Hope it helps
Upvotes: 1
Reputation: 7511
You might be trying / expecting to create a dict()
with j
as the the key.
Or, for multidimensional arrays, numpy
is very useful
See the dict() docs: http://docs.python.org/library/stdtypes.html#dict
Note:
> A(j) # this calls function A
> A[j] # this returns the list item 'j'
> A[j] = foo # this sets list item 'j' = foo
Upvotes: 0