Python Forum
List 3 dimensions reference does not work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List 3 dimensions reference does not work
#1
Hello, I am currently working on a program to plot some data in Python, and I have a little problem with referencing some values from an array of three dimensions.
Mi code, part of it, is the following:
for i in range(0,numberOfDistances):
    print(meanHeatFluxValue[0][i][0])
print(meanHeatFluxValue)
print("Uno=",meanHeatFluxValue[0][0][0])
print("Dos=",meanHeatFluxValue[0][1][0])
print("Tres=",meanHeatFluxValue[0][2][0])
print("Cuatro=",meanHeatFluxValue[0][3][0])
print("Cinco=",meanHeatFluxValue[0][4][0])
print("Total=",meanHeatFluxValue[0][0:5][0])
print("Total2=",meanHeatFluxValue[0][:][0])
print(peak1MHF[0:5])
and the results in console are:
Output:
14.481251700000001 13.911919666666668 10.831539999999999 7.2772367000000004 5.0994235 Uno= 14.481251700000001 Dos= 13.911919666666668 Tres= 10.831539999999999 Cuatro= 7.2772367000000004 Cinco= 5.0994235 Total= [14.481251700000001, 14.271817499999997, 14.1936564, 14.2394419, 14.2713967] Total2= [14.481251700000001, 14.271817499999997, 14.1936564, 14.2394419, 14.2713967][/inline]
I thought
print("Total=",meanHeatFluxValue[0][0:5][0])
print("Total2=",meanHeatFluxValue[0][:][0])
give me the values of the 5 first elements, the first one, and all the elements, the later, but it seems it is not working or I have misunderstood it.
Could somebody give me an answer why it is not working and how to solve it or make it work?
PD:
I have created a variable to save the values with the following code and with it is working, but I would like to make it work with the original list.
for d in range (0,numberOfDistances):   
        peak1MHF.append(meanHeatFluxValue[0][d][0]
Reply
#2
try
print("Total=", zip(meanHeatFluxValue[0][0:5])[0])
print("Total2=",meanHeatFluxValue[0])
swallow osama bin laden
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,332 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Beginner: Code not work when longer list raiviscoding 2 821 May-19-2023, 11:19 AM
Last Post: deanhystad
  How to work with list kafka_trial 8 2,018 Jan-24-2023, 01:30 PM
Last Post: jefsummers
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,648 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,558 Sep-07-2020, 08:02 AM
Last Post: perfringo
  how does .join work with list and dictionaries gr3yali3n 7 3,297 Jul-07-2020, 09:36 PM
Last Post: bowlofred
  A strange list, how does this work? Pedroski55 1 1,720 May-13-2020, 11:24 PM
Last Post: snippsat
  reference in pop function for linked list oloap 0 1,571 Mar-14-2020, 05:52 PM
Last Post: oloap
  set a new object node in a linked list via reference oloap 2 2,099 Mar-13-2020, 09:45 PM
Last Post: oloap
  Problem with List Reference CH_NoLuck 1 1,691 Feb-22-2020, 03:27 AM
Last Post: CH_NoLuck

Forum Jump:

User Panel Messages

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