[issue30930] Element wise multiplication issue
Ivan Marroquin
report at bugs.python.org
Fri Jul 14 09:21:15 EDT 2017
New submission from Ivan Marroquin:
Hi all,
I am using an anaconda 4.3.18 64 bits installation on windows 7. the version of python is 3.6.1 and numpy version is 1.12.1
In Python, I have this element wise multiplication:
import numpy as np
#read the input data from an ascii file into the attributes_data #variable
def rankorder(attribute):
sorted_items= np.sort(attribute, axis= 0, kind= 'mergesort')
sorted_ids= np.argsort(attribute,axis= 0, kind= 'mergesort')
# Find where are repetitions
repeat_ids= (np.diff(sorted_items) == 0).astype(int)
t_repeat_ids= [0]
t_repeat_ids.extend(repeat_ids)
# Rank with tieds with/withou skipping
rankNoSkip= np.logical_not(t_repeat_ids).astype(int)
rankNoSkip= np.cumsum(rankNoSkip)
# Pre-allocate rank
rank= np.arange(1, len(attribute) + 1)
# Adjust for tieds (and skips)
for i in range(0, len(rank)):
if (t_repeat_ids[i] == 1):
rank[i]= rankNoSkip[i]
new_rank= np.zeros((len(attribute),1), np.int)
for i in range(0, len(rank)):
new_rank[sorted_ids[i]]= rank[i]
return new_rank
rows= np.shape(attributes_data)[0]
R= rankorder(attributes_data[:,0])
S= rankorder(attributes_data[:,1])
A= np.zeros((rows), np.float64)
A= (R - 1) * (R - 2) * (S - 1) * (S - 2)
which for the first 20 and last 20 lines, I get:
[[ -490512836 -2014671888 45454500 88877908 168997500 -999033092
234376500 -1459172492 274758300 -1621798592 302597100 -1745619092
323687100 -1807113092 337229100 -1843876292 345487500 -1819378592
339970800 -1782548792]]
[[ 269791376 -882944896 -1010138236 -969282796 -132998296 -2128999336
62900136 25346184 1914059608 -1246247072 -2047681696 357533664
-1795623696 1896988000 767556900 757120 2046171488 365504
360674604 499699800 41184000]]
In Octave, I have the equivalent script. However, the computed values right at this command line:
A= (R - 1) .* (R - 2) .* (S - 1) .* (S - 2)
I get these results:
Columns 1 through 8:
1.6272e+011 1.0870e+010 4.5454e+007 8.6788e+009 1.6900e+008 7.5909e+009 2.3438e+008 7.1308e+009
Columns 9 through 16:
2.7476e+008 6.9681e+009 3.0260e+008 6.8443e+009 3.2369e+008 6.7828e+009 3.3723e+008 6.7461e+009
Columns 17 through 20:
3.4549e+008 6.7706e+009 3.3997e+008 6.8074e+009
ans =
Columns 1 through 8:
4.5648e+009 3.4120e+009 3.2848e+009 3.3257e+009 4.1620e+009 2.1660e+009 6.2900e+007 2.5346e+007
Columns 9 through 16:
1.0504e+010 7.3437e+009 2.2473e+009 3.5753e+008 2.4993e+009 1.8970e+009 7.6756e+008 7.5712e+005
Columns 17 through 21:
6.3411e+009 4.2953e+009 4.6556e+009 4.9970e+008 4.1184e+007
For some reason the computed values in Python are wrong. Any suggestions?
In the attached file, the first column corresponds to R variable and the second column corresponds to S variable.
Many thanks,
Ivan
----------
components: Interpreter Core
files: Python_Multiplication.zip
messages: 298353
nosy: ivan-marroquin
priority: normal
severity: normal
status: open
title: Element wise multiplication issue
type: performance
versions: Python 3.6
Added file: http://bugs.python.org/file47015/Python_Multiplication.zip
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30930>
_______________________________________
More information about the Python-bugs-list
mailing list