Why Numpy.asarray Return An Array Full Of Boolean
If I want to have an array filled whith 0 or 1 depending of the pixels value in a image, I write this : image = 'example.jpg' imageOpen = Image.open(image) bwImage = imageOpen.conv
Solution 1:
In a nutshell : In python True
is 1
and False
is 0
. This should correct this weird behavior :
bw_np = numpy.asarray(bwImage, dtype=int)
Long answer : Maybe imageOpen.convert("1", dither=Image.NONE)
prefer bool instead of int32 for a better memory management :
import sys
import numpy
print("Size of numpy.bool_() :", sys.getsizeof(numpy.bool_()))
print("Size of numpy.int32() :", sys.getsizeof(numpy.int32()))
Result :
Size of numpy.bool_() : 13
Size of numpy.int32() : 16
Post a Comment for "Why Numpy.asarray Return An Array Full Of Boolean"