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,550 points
36 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,190 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,060 points
552 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,550 points
1,213 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
165 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,550 points
52 views
0 votes
1 answer

Send CoAP requests using Python

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

answered Oct 15, 2018 in IoT (Internet of Things) by nirvana
• 3,060 points
144 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 413 views