Python Forum
python array/cell/indexing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python array/cell/indexing
#2
With numpy:
import numpy as np
shape = (2,5)
arr1 = np.zeros(shape)
print(arr1)
With stock Python:
shape = (2,5)
arr2 = []
fill_value = 0
for a in range(shape[0]):
    row = []
    for b in range(shape[1]):
        row.append(fill_value)
    arr2.append(row)
print(arr2)
Accessing multi dimensional lists with stock Python:
arr2[0][1]
arr2[0][0:2]
Same with numpy:
arr1[0,1]
arr1[0,0:2]
More complex stuff with numpy:

arr1[:,::2]
Returns all rows, from each row the even fields are selected.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
python array/cell/indexing - by python - Feb-08-2018, 07:40 AM
RE: python array/cell/indexing - by DeaD_EyE - Feb-08-2018, 11:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python read Excel cell data validation anantpatil 0 4,163 Jan-31-2020, 04:57 PM
Last Post: anantpatil
  Learning indexing with python, pick dates dervast 1 1,745 Jul-11-2019, 07:29 AM
Last Post: scidam
  Slicing String cell by cell Vigneshkumarsakthivel 0 2,394 Sep-02-2018, 05:59 PM
Last Post: Vigneshkumarsakthivel
  Importing matlab cell array (.mat) into a python list scanato 0 8,654 Nov-15-2017, 11:04 AM
Last Post: scanato

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020