yannis assael | the blog

  • Home
  • About
  • Categories
    • Android
    • Computing
    • iOS
    • Machine Learning
    • MacOSX
  • GitHub
  • Mobile Apps
  • yannisassael.com


Posts Tagged ‘python’

Open Python 2 Pickle in Python 3

Written by iassael on 30/03/2016. Posted in computing

Opening a pickle from Python 2 in Python 3 will probably result either:

TypeError: 'str' does not support the buffer interface

or

UnicodeDecodeError: 'ascii' codec can't decode byte 0xab in position 0: ordinal not in range(128)

to solve that you can just use the following code setting the defualt encoding:

import pickle
import gzip
import numpy as np
with open('var/python2pickle.pkl', 'rb') as f:
    data = pickle.load(f, encoding='latin1')
    print(data)

  • Continue Reading
  • No Comments

Heaviside Step Function between 0 and 1 in Python (if else mathematical expression)

Written by iassael on 23/02/2015. Posted in computing, machine learning

Dirac_distribution_CDF.svgThe numpy.sign() function returns a result between -1 and 1 which was not useful in my case…

To limit the outcomes in the range of 0 and 1 you could still use the numpy.sign() function and write it as follows:

(0.5 * (np.sign(var) + 1))

Cheers

  • Continue Reading
  • No Comments