>>> I want to create two arrays using the above file (Links array and Prob >>> array) that should give following output: >>> >>> *Links *= { [3,5] [5,4] [5,8] [7,8] [14,10] [14,13] [17,13] [14,18] >>> [10,13] [14,13] [17,13] [12,13] [11,6] [11,9][11,12] [11,19] [19,20] >>> [15,20] [21,20] [20,21] [21,16] [21,22] } >>> >>> *Prob *= {[0.28] [0.15] [0.08] [0.04] [0.04] [0.04] [0.08] [0.04] [0.08] >>> [0.08] [0.08] [0.08] [0.24] [0.24] [0.34] [0.27] [0.27]} >> >> >> I don't understand how you develop this? The first list has 22 items the >> second 17. I would have expected them to be the same? > > > In the "Prob" array the elements are less because if you read the note > below: I said the links that are repeating for example [3,5] their > probabilities get added and stored as a single value in the "Prob" array.
But what will you plan to do with these values afterwards? I think Alan's point here is that if there's no direct relationship between the elements in Links and the elements in Probs, those values aren't going to be very useful to solve the rest of the problem. One way to look at this problem is to simplify or normalize the input; the original structure in the file is slightly weird to process, since a single line of the input represents several link/failure pairs. One concrete example is: 4,10,13,14,13,17,13,12,13,0.04 where all these numbers are uninterpreted. You can imagine something that takes the line above, and breaks it down into a series of LinkFailure items. ###### class LinkFailure(object): """Represents a link and the probability of failure.""" def __init__(self, start, end, failure): self.start = start self.end = end self.failure = failure ###### which represent a link and failure structure. If we have a structure like this, then it explicitly represents a relationship between a link and its failure, and the string line: 4,10,13,14,13,17,13,12,13,0.04 can be distilled and represented as a collection of LinkFailure instances: [LinkFailure(10, 13, 0.04), LinkFailure(14, 13, 0.04), LinkFailure(17, 13, 0.04), LinkFailure(12, 13, 0.04)] Then the relationship is explicit. >> Also why do you want these two lists? What do you plan on doing with them? >> I would have thought a mapping of link to probability would be much more >> useful? (mapping => dictionary) > > > I want these two lists because using the links and probs array, I will check > which link has the lowest probability. Here lowest probability means the > risk of failure for that link. So based on which link has least probability > of failure, I will use it to setup a connection (I have a source and > destination and the links mentioned above are the paths between them) I want > to select the path which has least failure probability. > > Did it make sense? Unfortunately, I'm still confused. If you just have the Links and the Probs lists of unequal length, unless there's some additional information that you're represented, then I don't see the necessary connection between the two lists that lets you go any further in the problem. There's no one-to-one-ness: given a link in Links, which Probs do you want to look at? If you don't represent that linkage in some way, I don't understand yet where you go next. >>> So the first element in Links array is [3,5] and its probability of >>> failure is the first element in Prob array i.e. 0.28 But if the two lists are different lengths, what probability of failure is associates with the last element in the Prob array? The representation of data is important: if you choose an awkward representation, it makes solving this problem more difficult than it needs be. That is, if you're already compressing multiple elements in Prob that correspond to the same link, you also need some way to figure out what link that a compressed probability refer to. Otherwise, you don't have enough information to solve the problem anymore. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor