First of all the sample rate that you have provided is unreasonably large. Usual audio sampling frequencies are either $44,100 \:\texttt{kHz}$ or $48,000 \:\texttt{kHz}$, for example.
Secondly, yes, what you have identified here is an approach that is commonly used in digital signal processing to save memory and computational resources.
Here is my implementation at a lower (audible) frequency with a reasonable sampling rate:
import numpy as np
import pyaudio
frequency = 1000 #Freq in Hz
sample_rate = 48000 # Reasonable Sample rate
period = 1 / frequency
num_samples_per_period = int(period * sample_rate)
# Generate one period of sine wave
t = np.arange(0, period, 1/sample_rate)
sine_wave = np.sin(2 * np.pi * frequency * t)
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paFloat32,
channels=1,
rate=int(sample_rate),
output=True)
# Infinite loop
while True:
stream.write(sine_wave.astype(np.float32).tobytes())
stream.stop_stream()
stream.close()
p.terminate()
You can confirm that the correct signal is being generated correctly using this website. Also don't forget to pip install pyaudio