Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: generate_test_arrays.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script generates a file with 10 lines of arrays for testing purposes.
- Each array contains random floating-point numbers.
- Requirements:
- - Python 3.x
- Functions:
- - generate_random_arrays(num_arrays, array_length):
- Generates a list of arrays with random floating-point numbers.
- - save_arrays_to_file(arrays, filename):
- Saves the generated arrays to a file.
- Usage:
- - Run the script to generate a file named 'test_arrays.txt' in the current working directory.
- """
- import numpy as np
- def generate_random_arrays(num_arrays=10, array_length=10):
- """
- Generate a list of arrays with random floating-point numbers.
- Parameters:
- num_arrays (int): Number of arrays to generate.
- array_length (int): Length of each array.
- Returns:
- list: A list of arrays with random floating-point numbers.
- """
- generated_arrays = []
- for _ in range(num_arrays):
- random_array = np.random.uniform(low=-5.0, high=5.0, size=array_length).tolist()
- generated_arrays.append(random_array)
- return generated_arrays
- def save_arrays_to_file(arrays, filename='test_arrays.txt'):
- """
- Save the generated arrays to a file.
- Parameters:
- arrays (list): A list of arrays to save.
- filename (str): The name of the file to save the arrays to.
- """
- with open(filename, 'w', encoding='utf-8') as file:
- for index, array in enumerate(arrays, start=1):
- array_str = ', '.join(f'{x:.4f}' for x in array)
- file.write(f"{index} - Item {index} - [{array_str}]\n")
- if __name__ == "__main__":
- # Generate 10 arrays with 10 random floating-point numbers each
- num_arrays_to_generate = 10
- array_length_to_generate = 10
- arrays_to_save = generate_random_arrays(num_arrays_to_generate, array_length_to_generate)
- # Save the arrays to 'test_arrays.txt'
- save_arrays_to_file(arrays_to_save)
- print(f"Generated {num_arrays_to_generate} arrays and saved to 'test_arrays.txt'")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement