Just tell struct
how many float
s you have. 100k floats takes about a 1/100th of a second on my slow laptop.
import random
import struct
floatlist = [random.random() for _ in range(10**5)]
buf = struct.pack('%sf' % len(floatlist), *floatlist)
Related Contents:
- packing and unpacking variable length array/string using the struct module in python
- PyLint message: logging-format-interpolation
- How do I format a string using a dictionary in python-3.x?
- Difference between except: and except Exception as e:
- How to set the timezone in Django
- pip or pip3 to install packages for Python 3?
- How to check if variable is string with python 2 and 3 compatibility [duplicate]
- How To Check If A Key in **kwargs Exists?
- Convert bytes to int?
- How to downgrade python from 3.7 to 3.6
- virtualenvwrapper and Python 3
- Will OrderedDict become redundant in Python 3.7?
- Why is str.translate much faster in Python 3.5 compared to Python 3.4?
- How to test Python 3.4 asyncio code?
- Handle JSON Decode Error when nothing returned
- Python – Get Yesterday’s date as a string in YYYY-MM-DD format
- Django – No such table: main.auth_user__old
- What exactly is __weakref__ in Python?
- Infinite integer in Python
- I can’t install pyaudio on Windows? How to solve “error: Microsoft Visual C++ 14.0 is required.”?
- Get exit code and stderr from subprocess call
- How do I create documentation with Pydoc?
- What does it mean to “run library module as a script” with the “-m” option? [duplicate]
- Mayavi colorbar in TraitsUI creating blank window
- URL Decode with Python 3
- The zip() function in Python 3
- ModuleNotFoundError with pytest
- Why doesn’t Python give any error when quotes around a string do not match?
- Convert from ‘_io.BytesIO’ to a bytes-like object in python3.6?
- python typing signature (typing.Callable) for function with kwargs
- Removing non numeric characters from a string
- Want to find contours -> ValueError: not enough values to unpack (expected 3, got 2), this appears [duplicate]
- How can I make a for-loop pyramid more concise in Python? [duplicate]
- Error when checking target: expected dense_3 to have shape (3,) but got array with shape (1,)
- How are you planning on handling the migration to Python 3?
- Download YouTube video using Python to a certain directory
- Need a fast way to count and sum an iterable in a single pass
- How do the scoping rules work with classes?
- Is super() broken in Python-2.x? [closed]
- Which tkinter modules were renamed in Python 3?
- Python string argument without an encoding
- Anaconda Installed but Cannot Launch Navigator
- Self-reference or forward-reference of type annotations in Python [duplicate]
- Make every field as optional with Pydantic
- Most Pythonic way to declare an abstract class property
- Why do I get an int when I index bytes?
- Detect If Item is the Last in a List [duplicate]
- Python decorator? – can someone please explain this? [duplicate]
- Python & Pandas – Group by day and count for each day
- TypeError: ‘encoding’ is an invalid keyword argument for this function