0

so I am working on finding the sigmoid equation for logistic regression for matrices. I have two matrices, z and g, and would like to replace the values in g with the sigmoid values. I have the following code, but cannot figure out how to replace the elements in g with its respective sigmoid value. Any help would be appreciated!

I have the following:

z = np.array([[1, 4, 5, 12], [-5, 8, 9, 10], [-6, 7, 11, 19]])
g = np.zeros(z.shape)
for row in z:
    for i in row:       
    sigmoid = 1/(1+np.exp(-i))
desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

1

You can do it without a loop:

z = np.array([[1, 4, 5, 12], [-5, 8, 9, 10], [-6, 7, 11, 19]])
g = 1/(1+np.exp(-z))
Gil Pinsky
  • 2,388
  • 1
  • 12
  • 17