Numpy.eye() in Python 3

I'm using numpy.eye(N, M, dtype=int) to print a matrix whose diagonal elements are 1 and rest of the elements are 0. Code:

import numpy
import sys

line = sys.stdin.readline()

N, M = map(int, line.split())

print numpy.eye(N, M, dtype=int)

The above runs successfully in Python 2. But in python 3 I get the following error:

File "solution.py", line 7
    print numpy.eye( N , M , dtype =int )
              ^
SyntaxError: invalid syntax

Is there an alternate package other than numpy in Python 3 through which I can accomplish this? Has the eye function become obsolete with Python 3?

Topic programming python data-mining

Category Data Science


No, the print function has changed; it needs to be treated as a proper function, with parentheses. Try:

print(numpy.eye(N, M, dtype=int))

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.