Python numpy matrix assign value -


i wondering why different result in 2 prints? shouldn't same?

    import numpy np      x = np.array([[1.5, 2], [2.4, 6]])      k = np.copy(x)     in range(len(x)):        j in range(len(x[i])):             k[i][j] = 1 / (1 + np.exp(-x[i][j]))             print("k[i][j]:"+str(k[i][j]))             print("value:"+str(1 / (1 + np.exp(-x[i][j])))) 

i've run code python3 , python2 , results absolutely same. besides, don't have looping when using numpy arrays allows express many kinds of data processing tasks concise array expressions might otherwise require writing loops. practice of replacing explicit loops array expressions commonly referred vectorization. in general, vectorized array operations 1 or 2 (or more) orders of magnitude faster pure python equivalents, biggest impact in kind of numerical computations.

so, keeping in mind may rewrite code follows:

import numpy np  x = np.array([[1.5, 2], [2.4, 6]], dtype=np.float) k = 1 / (1 + np.exp(-x)) 

Comments

Popular posts from this blog

php - Autoloader issue not returning Class -

C++ Program To Find Smallest and Largest Number In Array -

java - How to put two numbers separated by a space into two different arrays -