-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtensor_operations.py
36 lines (32 loc) · 978 Bytes
/
tensor_operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import inspect
def analyze_tensor(input_tensor):
'''
Input:
input_tensor - The tensor to be analyzed.
Output:
None
Func:
This function analyzes the given input tensor and prints information about it.
It outputs the variable name of the tensor, its shape, and its content.
'''
print("\n##### analyze_tensor_st #####")
# Output the variable name
print("1.Name:")
frame = inspect.currentframe().f_back
var_name = 'Unable'
for name, value in frame.f_locals.items():
if value is input_tensor:
var_name = name
break
print(var_name)
# Shape of the tensor
print("2.Shape:")
print(tuple(input_tensor.shape))
# Content of the tensor
tensor_content = input_tensor.tolist()
print("3.Content:")
print(str(input_tensor))
print("##### analyze_tensor_ed #####")
def analyze_tensor_s(*args):
for Unable in args:
analyze_tensor(Unable)