Can you be 100% certain that a payment was sent from a specific address? Reading this thread about determining the sending address of a bitcoin transaction. I'm a bit confused, how do you differentiate between the change address and the "receiving" address of the last transaction?

txid = &lt;relevant transaction id&gt;
addresses = []
raw_tx = decoderawtransaction(getrawtransaction(txid))
for(input in raw_tx['vin']) {
  input_raw_tx = decoderawtransaction(getrawtransaction(input['txid']))
  addresses.push(input_raw_tx['vout'][input['vout']]['scriptPubKey']['addresses'] [0])
}


Would addresses not include other outputs that are unrelated to the sending address? I'm trying to build a block explorer and I'm uncertain how to determine which address sent coins in each transaction. Is it possible to tell?
From the Bitcoin Wiki:


  An input is a reference to an output in a different transaction. 


A transaction can have multiple outputs, e.g., a normal one and the change, which specify the recipient address in their scriptPubKey. So usually to each output belongs one address, and the input specifies which output it redeems.

If an output specifies multiple destination addresses (which is rarely the case), only one of those can redeem the transaction. You can find out which one by looking at the scriptSig of the input.