0

I have a one dimensional array called monteCarloPerf which can look something like:

monteCarloPerf  [[113.4848779294831], [169.65800173373898], [211.35999049731927], [169.65800173373901], [229.66974328119005]]

I am retrieving a single element from the array using:

finalValue = monteCarloPerf[arrayValue]

where arrayValue is an integer.

Say arrayValue = 0, at the moment I am getting returned : [113.4848779294831]. Is there a way to just return the float without the brackets please? So I would be returned just 113.4848779294831.

Many thanks

1
  • moteCarloPerf[arrayValue][0]? Commented Sep 2, 2015 at 7:37

4 Answers 4

1

Your object monteCarloPerf is a one dimensional array containing elements of one dimensional arrays, or a list of lists. In order to access the value of the first element of the object you have to change your access to that element to the following:

finalValue = monteCarloPerf[arrayValue][0]
Sign up to request clarification or add additional context in comments.

Comments

1

In fact, that is a 'TWO dimensional' array.

To get the float value you can do the following:

finalValue = monteCarloPerf[arrayValue][0]

Or you can transform the two dimensional array to a one dimensional array:

one_dim = [item[0] for item in monteCarloPerf]

I hope this helps.

Comments

0

monteCarloPerf is a list of list. When you are using monteCarloPerf[index] it is returning list at index position. Based on the symmetry in your list, in each sub-list, item at [0] position is the actual value you are trying to fetch.

Use this to fetch the value

finalValue = monteCarloPerf[arrayValue][0]

Comments

0

Here's a weird way to do this without using list.__getitem__() method:

float(''.join(i for i in str(monteCarloPerf[arrayValue])))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.