from numpy import where


__all__ = ('sign2bin', 'bin2sign', 'hopfield_energy')


def sign2bin(matrix):
    return where(matrix == 1, 1, 0)


def bin2sign(matrix):
    return where(matrix == 0, -1, 1)


def hopfield_energy(weight, input_data, output_data):
    energy_output = -0.5 * input_data.dot(weight).dot(output_data.T)
    return energy_output.item(0)

from numpy import where, inner
from numpy.core.umath_tests import inner1d


__all__ = ('sign2bin', 'bin2sign', 'hopfield_energy')


def sign2bin(matrix):
    return where(matrix == 1, 1, 0)


def bin2sign(matrix):
    return where(matrix == 0, -1, 1)


def hopfield_energy(weight, input_data, output_data):
    return -0.5 * inner1d(input_data.dot(weight), output_data)

Fix problem with Hopfield energy function for Python 2.7
Fix problem with Hopfield energy function for Python 2.7

- from numpy import where
+ from numpy import where, inner
+ from numpy.core.umath_tests import inner1d
  
  
  __all__ = ('sign2bin', 'bin2sign', 'hopfield_energy')
  
  
  def sign2bin(matrix):
      return where(matrix == 1, 1, 0)
  
  
  def bin2sign(matrix):
      return where(matrix == 0, -1, 1)
  
  
  def hopfield_energy(weight, input_data, output_data):
+     return -0.5 * inner1d(input_data.dot(weight), output_data)
-     energy_output = -0.5 * input_data.dot(weight).dot(output_data.T)
-     return energy_output.item(0)
  
Fix problem with Hopfield energy function for Python 2.7
## Code Before:
from numpy import where


__all__ = ('sign2bin', 'bin2sign', 'hopfield_energy')


def sign2bin(matrix):
    return where(matrix == 1, 1, 0)


def bin2sign(matrix):
    return where(matrix == 0, -1, 1)


def hopfield_energy(weight, input_data, output_data):
    energy_output = -0.5 * input_data.dot(weight).dot(output_data.T)
    return energy_output.item(0)

## Instruction:
Fix problem with Hopfield energy function for Python 2.7
## Code After:
from numpy import where, inner
from numpy.core.umath_tests import inner1d


__all__ = ('sign2bin', 'bin2sign', 'hopfield_energy')


def sign2bin(matrix):
    return where(matrix == 1, 1, 0)


def bin2sign(matrix):
    return where(matrix == 0, -1, 1)


def hopfield_energy(weight, input_data, output_data):
    return -0.5 * inner1d(input_data.dot(weight), output_data)
