Python Short Integers

0 votes
I have a huge dataset which needs to be fully loaded into memory and Python allocates integers automatically based on the underlying system architecture.

So, can I force Python to use only 2 bytes for some integers (an equivalent of C++ 'short')?
Sep 18, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
2,470 views

1 answer to this question.

0 votes

Firstly, if you're doing any sort of manipulation of this huge dataset, you'll probably want to use Numpy, which has support for a wide variety of numeric types, and efficient operations on arrays of them.

And the answer to your question,

from array import array
a = array("h") # h = signed short, H = unsigned short

As long as the value stays in that array, it will be a short integer.

PS: C++'s short not 2 bytes width. It's implementation dependent.

answered Sep 18, 2018 by Annie97
• 2,160 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Sending CoAP requests using Python

It can be done using a library ...READ MORE

answered Aug 24, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
2,551 views
0 votes
1 answer

How to trigger Python script on Raspberry Pi from Node-Red

Node-RED supplies an exec node as part ...READ MORE

answered Sep 14, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
3,237 views
0 votes
1 answer

Python Code to retrieve data from Device to IBM Bluemix

You connect as a device -> import ibmiotf.device. ...READ MORE

answered Sep 18, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,260 views
0 votes
1 answer

Does executable exist in Python?

This is a way I can think ...READ MORE

answered Sep 21, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,218 views
0 votes
1 answer

Send CoAP requests using Python

You can use a library like CoAPython ...READ MORE

answered Oct 16, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,783 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,342 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP