0

i have a problem, i have a project for the University and i get different values when i run my Mac version of python compiler and the Windows version of the python compiler.

Python version : 2.7 Libraries : Numpy

any clues ?

p161 and pNUMBER are arrays with [0,1,2] coordinates in numpy The code I have:

#PASO 38
print OPCION
print "PASO 38 - ESTRUCTURA DE COSTOS TOTALES POR PRODUCTO [ DATOS EXPRESADOS EN PORCENTAJES DEL COSTO TOTAL DEL PRODUCTO ]"
print
paso38517=numpy.array([100*p161[0]/p351[0],100*p231[0]/p351[0],100*p301[0]/p351[0]])
paso38525=numpy.array([100*p161[1]/p351[1],100*p231[1]/p351[1],100*p301[1]/p351[1]])
paso38535=numpy.array([100*p161[2]/p351[2],100*p231[2]/p351[2],100*p301[2]/p351[2]])

print     "TIPO              517    525    535"
print     "_____________________________________"
print str("MATERIA PRIMA   : ")+ numpy.array_str(paso38517[0])+str("%    ")+numpy.array_str(paso38525[0])+str("%    ")+numpy.array_str(paso38535[0])+str("%")
print str("MANO DE OBRA    : ")+ numpy.array_str(paso38517[1])+str("%    ")+numpy.array_str(paso38525[1])+str("%    ")+numpy.array_str(paso38535[1])+str("%")
print str("USO DE MAQUINA  : ")+ numpy.array_str(paso38517[2])+str("%     ")+numpy.array_str(paso38525[2])+str("%     ")+numpy.array_str(paso38535[2])+str("%")
print     "_____________________________________"
print
#PASO 39
paso39=numpy.array([100*mp1/costofinal,100*mo1/costofinal,100*um1/costofinal])
print OPCION
print "PASO 39 - ESTRUCTURA DE COSTOS TOTAL [ DATOS EXPRESADOS EN PORCENTAJES DE LOS COSTOS TOTALES ]"
print
print     "TIPO                COSTO"
print     "____________________________"
print str("MATERIA PRIMA   : ")+ numpy.array_str(paso39[0])+str("%")
print str("MANO DE OBRA    : ")+ numpy.array_str(paso39[1])+str("%")
print str("USO DE MAQUINA  : ")+ numpy.array_str(paso39[2])+str("%")
print     "____________________________"
print 

The same on windows and mac, after that i have some prints

PRINT ON MAC:

OXICORTE - SOLDADURA MANUAL
PASO 38 - ESTRUCTURA DE COSTOS TOTALES POR PRODUCTO [ DATOS EXPRESADOS EN PORCENTAJES DEL COSTO TOTAL DEL PRODUCTO ]

TIPO              517    525    535
_____________________________________
MATERIA PRIMA   : 76%    76%    73%
MANO DE OBRA    : 17%    17%    20%
USO DE MAQUINA  : 6%     6%     6%
_____________________________________

OXICORTE - SOLDADURA MANUAL
PASO 39 - ESTRUCTURA DE COSTOS TOTAL [ DATOS EXPRESADOS EN PORCENTAJES DE LOS COSTOS TOTALES ]

TIPO                COSTO
____________________________
MATERIA PRIMA   : 75%
MANO DE OBRA    : 17%
USO DE MAQUINA  : 6%
____________________________

PRINT ON WINDOWS:

OXICORTE - SOLDADURA MANUAL
PASO 38 - ESTRUCTURA DE COSTOS TOTALES POR PRODUCTO [ DATOS EXPRESADOS EN PORCENTAJES DEL COSTO TOTAL DEL PRODUCTO ]

TIPO              517    525    535
_____________________________________
MATERIA PRIMA   : **-2%**    **16%**    73%
MANO DE OBRA    : **-9%**    **17%**    20%
USO DE MAQUINA  : 6%     6%     6%
_____________________________________

OXICORTE - SOLDADURA MANUAL
PASO 39 - ESTRUCTURA DE COSTOS TOTAL [ DATOS EXPRESADOS EN PORCENTAJES DE LOS COSTOS TOTALES ]

TIPO                COSTO
____________________________
MATERIA PRIMA   : **-8%**
MANO DE OBRA    : **1%**
USO DE MAQUINA  : 6%
____________________________

UPDATE:

all the arrays are OK in both OS, the problem is with p161[0]/p351[0] and the other divisions, in MAC i get 0.76 and in Windows 0.0, and then after that when i do the *100, in windows i get -2 as output.

This example is on PASO38 MATERIA PRIMA 517.

4

1 回答 1

3

问题在于 p161[0]/p351[0] 和其他部门。在 Mac 上我得到 0.76,在 Windows 上得到 0.0。

这听起来很像您的除法运算符在 Mac 上执行浮点除法并在 Windows 上截断整数除法。如果你在 Mac 上运行 Python 3,在 Windows 上运行 Python 2,就会发生这种情况。但是旧式的print陈述却暗示了相反的情况。如果你执行了它也会发生

from __future__ import division

在 Mac 上,但不在 Windows 代码中。

由于您显然想要浮点除法,因此您应该在任何地方执行以下操作之一:

  1. 使用 Python 3/总是意味着真正的浮点除法。
  2. 使用from __future__ import division.
  3. float在执行除法之前将您的操作数之一转换为。
于 2013-06-30T20:17:06.797 回答