Hi
- User
Hi
- Assistant
Hello! How can I assist you today?
- User
give me a python code to generate rotation matrix given an input in angle
- Assistant
Certainly! Here's a Python code to generate a 2D rotation matrix given an input angle:
pythonimport math def rotation_matrix(angle): # Converting angle to radians theta = math.radians(angle) # Generating rotation matrix cos_theta = math.cos(theta) sin_theta = math.sin(theta) rotation_matrix = [[cos_theta, -sin_theta], [sin_theta, cos_theta]] return rotation_matrix # Example usage angle = 45 # Input angle in degrees matrix = rotation_matrix(angle) print(matrix)This code uses the math module in Python to compute the sine and cosine of the angle. It then constructs the rotation matrix using these values. The resulting rotation matrix is a 2x2 matrix that performs a rotation by the specified angle.
You can change the value of the
anglevariable to generate rotation matrices for different angles. The resulting matrix is printed to the console for demonstration purposes. - User
python code to store array as binary file
- Assistant
Certainly! Here's a Python code snippet to store an array as a binary file:
pythonimport numpy as np def write_array_to_binary_file(array, filename): """ Writes a NumPy array to a binary file. Parameters: array (numpy.ndarray): The array to be stored. filename (str): The name of the binary file. """ with open(filename, 'wb') as file: # Save the shape of the array as metadata shape = array.shape shape_bytes = np.array(shape).tobytes() file.write(shape_bytes) # Save the array data array.tofile(file) # Example usage data = np.array([1, 2, 3, 4, 5]) filename = 'array_data.bin' write_array_to_binary_file(data, filename)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.