Contents tagged with Python

  • Functions map, zip and lambda in Python

    Hello everybody,

    today I want to describe three elements of Python: map, zip, lambda and *.

    Zip and *

    The first step that I want to describe is zip and * usage. Take a look at the following code:

    a = [5, 6]

    b = [7, 8]

    c = zip(a,b)


    How do you think, what will be output, if I'll tell you that zip function zips arrays? If your guess is (5, 6) (7, 8) then unfortunately you are wrong. Output will be the following:

    (5, 7) (6, 8). I suppose that zip name was chosen because as usually zippers on clothes as usually vertical. Zip functions "zips" elements by columns, like presented on the picture:

    Now one more question, what is purpose of * ? It tells to Python interpreter to … more

  • How to read little endian file of floats in Java

    Hello everybody,

    today I want to document another issue that took from me plenty of time. Recently I've used following code in Python in order to save array of numpy numbers:

    import numpy as np

    newImage = ...some way of getting array

    np.ndarray.tofile(newImage, newFn)

    But when I tried to get that content in Java code, I faced issue that my inputs where unreadable by Java. After spending some time over net I've found that Python uses little endian encoding, while Java uses another encoding for saving floats. 

    So my research of little endian gave me the following code result in java for reading little endian:

    InputStream inputStream = null;DataInputStream dataInputStream = null; … more