Print format using NumPy in Python

I want to create a 2d dimensional array in NumPy size 128x2and store long integers in it (each integer has a size of 128 bits).

CODE:

keys = np.zeros(shape=(128, 2))
for i in range(0, 128):

    key1 = random.randrange(1 << 127, 1 << 128)
    key2 = random.randrange(1 << 127, 1 << 128)

    keys[i, 0] = key1
    keys[i, 1] = key2

print(keys)

The random key has the following output:

212325597117085680729458082297541802625

However, when I print an array of keys, I got the following output:

EXIT:

[[  3.24916136e+38   1.88464325e+38]
 [  3.01375156e+38   2.73451722e+38]
 [  1.85204001e+38   2.47016718e+38]
 [  1.85813038e+38   2.66817805e+38]
 [  1.93774249e+38   2.62902937e+38]
 [  2.77003163e+38   2.13490918e+38]
 [  1.92502885e+38   3.28965325e+38]
 [  3.03869869e+38   2.27308256e+38]
 [  2.97958126e+38   2.50477741e+38]
 [  1.82747542e+38   2.17062238e+38]
 [  2.59264124e+38   3.17242510e+38]
 [  2.43152125e+38   3.33742346e+38]
etc

How to print keys in source format?

+4
source share
1 answer

You have two questions with your code.

-, dtype . dtype , np.zeros, float64, , . , , .

, numpy 128- . , . dtype uint64 ( , ). , , dtype. object dtype Python int ( , , numpy).

- ( ). np.set_printoptions, , , dtype, numpy. - , .

0

Source: https://habr.com/ru/post/1611455/


All Articles