Operating environment
Xeon E5-2620 v4 (8 cores) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 and its-devel
mpich.x86_64 3.1-5.el6 and its-devel
gcc version 4.4.7 (And gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Use 1.
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
Python 3.6.0 on virtualenv
The code below was fine in Python 2.
test_numpy_170317.py
#!/usr/bin/env python
import numpy as np
vals = map(float, [3., 1., 4.])
total_val = np.sum(vals)
print('total: %.2f' % total_val)
When I run it in Python 3, I get the following error:
Traceback (most recent call last):
File "test_numpy_170317.py", line 7, in <module>
print('total: %.2f' % total_val)
TypeError: must be real number, not map
In Python 2, what map () returns is a list object. In Python 3, what is returned by map () seems to be a map object.
Reference http://stackoverflow.com/questions/1303347/getting-a-map-to-return-a-list-in-python-3-x
By enclosing the map object in list (), the error disappeared.
test_numpy_170317.py
#!/usr/bin/env python
import numpy as np
vals = list(map(float, [3., 1., 4.]))
total_val = np.sum(vals)
print('total: %.2f' % total_val)
Recommended Posts