Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 python array/cell/indexing
Hello fellow programmers!

I recently started to learn python (previousely matlab) and I was hopeing some of you might be able help me with a specific problem.

I am trying to create a list in which each element contains a matrix.
I then want to access each entry seperately.

Easier with example I think.

All values are integer.

So I want a list shape = (n,).
-> Each element of that list I want to be a matrix (shape = (n,n)).
-> Now I want to access the first element of that list (so list(0,0) = first matrix).
-> Additionally I want to access each value of the selected matrix seperately.
So bsically my 0,0 listelement and my 0,0 matrixelement --- this should be an integer value

Does python approve or not?
With numpy:
import numpy as np
shape = (2,5)
arr1 = np.zeros(shape)
With stock Python:
shape = (2,5)
arr2 = []
fill_value = 0
for a in range(shape[0]):
    row = []
    for b in range(shape[1]):
Accessing multi dimensional lists with stock Python:
Same with numpy:
More complex stuff with numpy:

Returns all rows, from each row the even fields are selected.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die:
All humans together. We don't need politicians!

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Learning indexing with python, pick dates dervast 1 222 Jul-11-2019, 07:29 AM
Last Post: scidam
  Pandas Indexing with duplicates energerecontractuel 3 427 Mar-07-2019, 12:57 AM
Last Post: scidam
  future warning when using numpy fancy indexing bluefrog 0 1,047 Nov-20-2018, 09:44 AM
Last Post: bluefrog
  Slicing String cell by cell Vigneshkumarsakthivel 0 563 Sep-02-2018, 05:59 PM
Last Post: Vigneshkumarsakthivel
  Importing matlab cell array (.mat) into a python list scanato 0 3,434 Nov-15-2017, 11:04 AM
Last Post: scanato

Forum Jump:

Users browsing this thread: 1 Guest(s)