Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Convertion of an array into binary using NumPy binary_repr

# welcome to softhunt.net
# Python program explaining
# binary_repr() function
import numpy as np

arr = [12, -33 ]

print ("Input array : ", arr)

# binary representation of first array
# element without using width parameter
ans = np.binary_repr(arr[0])
print ("Binary representation of 12 Without using width parameter : ", ans)

# binary representation of first array
# element using width parameter
ans = np.binary_repr(arr[0], width = 7)
print ("Using width parameter: ", ans)


# binary representation of 2nd array
# element without using width parameter
ans = np.binary_repr(arr[1])
print ("Binary representation of -33 Without using width parameter : ", ans)

# binary representation of 2nd array
# element using width parameter
ans = np.binary_repr(arr[1], width = 7)
print ("Using width parameter : ", ans)
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Convertion #array #binary #NumPy
ADD COMMENT
Topic
Name
4+1 =