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
• 7,680 points
18 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,040 points
220 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
• 7,680 points
702 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,260 points
38 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
• 7,680 points
21 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,040 points
53 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
24 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.