import numpy as np
def partition_vector(vector, N):
"""
Partition a vector into a hypercube of side length N.
Args:
vector (np.array): The input vector.
N (float): The side length of each hypercube.
Returns:
tuple: A tuple of integers representing the coordinates of the hypercube.
"""
return tuple(np.floor(vector / N).astype(int))
def hypercube_info(vector, N):
"""
Get information about the hypercube a vector falls into.
Args:
vector (np.array): The input vector.
N (float): The side length of each hypercube.
Returns:
dict: A dictionary containing information about the hypercube.
"""
cube_coords = partition_vector(vector, N)
return {
"coordinates": cube_coords,
"lower_bound": np.array(cube_coords) * N,
"upper_bound": (np.array(cube_coords) + 1) * N,
"center": (np.array(cube_coords) + 0.5) * N
}
# Example usage
if __name__ == "__main__":
vector = np.array([3.7, -4.5, 5.6, -4.7])
N = 3.0
result = hypercube_info(vector, N)
print(f"Vector: {vector}")
print(f"Hypercube side length: {N}")
print(f"Hypercube coordinates: {result['coordinates']}")
print(f"Lower bound: {result['lower_bound']}")
print(f"Upper bound: {result['upper_bound']}")
print(f"Center: {result['center']}")
def partition_vector(vector, N):
"""
Partition a vector into a hypercube of side length N.
Args:
vector (np.array): The input vector.
N (float): The side length of each hypercube.
Returns:
tuple: A tuple of integers representing the coordinates of the hypercube.
"""
return tuple(np.floor(vector / N).astype(int))
def hypercube_info(vector, N):
"""
Get information about the hypercube a vector falls into.
Args:
vector (np.array): The input vector.
N (float): The side length of each hypercube.
Returns:
dict: A dictionary containing information about the hypercube.
"""
cube_coords = partition_vector(vector, N)
return {
"coordinates": cube_coords,
"lower_bound": np.array(cube_coords) * N,
"upper_bound": (np.array(cube_coords) + 1) * N,
"center": (np.array(cube_coords) + 0.5) * N
}
# Example usage
if __name__ == "__main__":
vector = np.array([3.7, -4.5, 5.6, -4.7])
N = 3.0
result = hypercube_info(vector, N)
print(f"Vector: {vector}")
print(f"Hypercube side length: {N}")
print(f"Hypercube coordinates: {result['coordinates']}")
print(f"Lower bound: {result['lower_bound']}")
print(f"Upper bound: {result['upper_bound']}")
print(f"Center: {result['center']}")