I imported the file edges.pkl for my code. I wish to understand the type/nature of this file which I am storing in edges . For this I've tried to print the following code. Can someone help me in understanding the type of this file? So that I can further process it! I want to slice the edges file into a smaller file (with less entries) so that I can run it with less computational resources!
Code:
with open('data/'+args.dataset+'/edges.pkl','rb') as f:
edges = pickle.load(f)
print('.......')
isinstance(edges, list)
print('edges',len(edges))
print('edges_shape',np.shape(edges))
print('1:5',edges[1::5])
print('1:2',edges[1::2])
print('edges_0',(edges[0,:]))
print('edges_1',len(edges[1]))
print('.......')
Error:
.......
edges 4
edges_shape (4,)
1:5 [<18405x18405 sparse matrix of type '<class 'numpy.int64'>' with 19645 stored elements in Compressed Sparse Column format>]
1:2 [<18405x18405 sparse matrix of type '<class 'numpy.int64'>' with 19645 stored elements in Compressed Sparse Column format>, <18405x18405 sparse matrix of type '<class 'numpy.int64'>' with 14328 stored elements in Compressed Sparse Column format>]
Traceback (most recent call last): File "/Users/anshumansinha/Desktop/GTN_gatech/main.py", line 66, in print('edges_0',(edges[0,:])) TypeError: list indices must be integers or slices, not tuple
.. Additional code:
num_nodes = edges[0].shape[0]
print('num_nodes', num_nodes)
for i,edge in enumerate(edges): # i goesthrough numbers [0,1,2,3...] and edge through edges.
print('i',i)
print('edge.shape', edge.shape)
print('edge',edge)
if i ==0:
A = tf.expand_dims(tf.convert_to_tensor(edge.todense(), dtype= tf.float32), -1)
else:
A = tf.concat((A,tf.expand_dims(tf.convert_to_tensor(edge.todense(), dtype= tf.float32), -1)), -1)
A = tf.concat((A, tf.expand_dims(tf.convert_to_tensor(tf.eye(num_nodes), dtype= tf.float32), -1) ), -1)
print('shape',A.shape)
Output: ...
num_nodes 18405
i 0
edge.shape = (18405, 18405)
edge (4057, 438) 1
(4058, 1945) 1
(4059, 866) 1
(4059, 1945) 1
(4060, 472) 1
(4060, 1299) 1
(4060, 2250) 1
(4061, 1415) 1
(4062, 2437) 1
(4063, 289) 1
(4064, 3381) 1
(4064, 3852) 1
(4065, 1605) 1
(4066, 1317) 1
(4066, 3355) 1
(4067, 2898) 1
(4068, 3951) 1
(4069, 1746) 1
(4070, 3041) 1
(4071, 468) 1
(4072, 1809) 1
(4073, 1352) 1
(4074, 1352) 1
(4075, 747) 1
(4076, 1890) 1
: :
(18367, 4001) 1
(18368, 3169) 1
(18369, 206) 1
(18370, 107) 1
(18370, 2020) 1
(18371, 1532) 1
(18372, 1671) 1
(18373, 1599) 1
(18374, 582) 1
(18374, 1963) 1
(18375, 920) 1
(18376, 1590) 1
(18376, 3044) 1
(18377, 248) 1
(18378, 596) 1
(18379, 2690) 1
(18380, 1434) 1
(18381, 470) 1
(18381, 2766) 1
(18382, 1547) 1
(18383, 3350) 1
(18384, 334) 1
(18384, 470) 1
(18384, 1590) 1
(18384, 3044) 1
2022-07-10 16:58:36.500345: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
i 1
edge.shape = (18405, 18405)
edge (438, 4057) 1
(1945, 4058) 1
(866, 4059) 1
(1945, 4059) 1
(472, 4060) 1
(1299, 4060) 1
(2250, 4060) 1
(1415, 4061) 1
(2437, 4062) 1
(289, 4063) 1
(3381, 4064) 1
(3852, 4064) 1
(1605, 4065) 1
(1317, 4066) 1
(3355, 4066) 1
(2898, 4067) 1
(3951, 4068) 1
(1746, 4069) 1
(3041, 4070) 1
(468, 4071) 1
(1809, 4072) 1
(1352, 4073) 1
(1352, 4074) 1
(747, 4075) 1
(1890, 4076) 1
: :
(4001, 18367) 1
(3169, 18368) 1
(206, 18369) 1
(107, 18370) 1
(2020, 18370) 1
(1532, 18371) 1
(1671, 18372) 1
(1599, 18373) 1
(582, 18374) 1
(1963, 18374) 1
(920, 18375) 1
(1590, 18376) 1
(3044, 18376) 1
(248, 18377) 1
(596, 18378) 1
(2690, 18379) 1
(1434, 18380) 1
(470, 18381) 1
(2766, 18381) 1
(1547, 18382) 1
(3350, 18383) 1
(334, 18384) 1
(470, 18384) 1
(1590, 18384) 1
(3044, 18384) 1
i 2
edge.shape = (18405, 18405)
edge (4057, 18385) 1
(4058, 18385) 1
(4059, 18385) 1
(4060, 18385) 1
(4061, 18385) 1
(4062, 18385) 1
(4063, 18385) 1
(4064, 18385) 1
(4065, 18385) 1
(4066, 18385) 1
(4067, 18385) 1
(4068, 18385) 1
(4069, 18385) 1
(4070, 18385) 1
(4071, 18385) 1
(4072, 18385) 1
(4073, 18385) 1
(4074, 18385) 1
(4075, 18385) 1
(4076, 18385) 1
(4077, 18385) 1
(4078, 18385) 1
(4079, 18385) 1
(4080, 18385) 1
(4081, 18385) 1
: :
(18360, 18403) 1
(18361, 18403) 1
(18362, 18403) 1
(18363, 18403) 1
(18364, 18403) 1
(18365, 18403) 1
(18366, 18403) 1
(18367, 18403) 1
(18368, 18403) 1
(18369, 18403) 1
(18370, 18403) 1
(18371, 18403) 1
(18372, 18403) 1
(18373, 18403) 1
(18374, 18404) 1
(18375, 18404) 1
(18376, 18404) 1
(18377, 18404) 1
(18378, 18404) 1
(18379, 18404) 1
(18380, 18404) 1
(18381, 18404) 1
(18382, 18404) 1
(18383, 18404) 1
(18384, 18404) 1
i 3
edge.shape = (18405, 18405)
edge (18385, 4057) 1
(18385, 4058) 1
(18385, 4059) 1
(18385, 4060) 1
(18385, 4061) 1
(18385, 4062) 1
(18385, 4063) 1
(18385, 4064) 1
(18385, 4065) 1
(18385, 4066) 1
(18385, 4067) 1
(18385, 4068) 1
(18385, 4069) 1
(18385, 4070) 1
(18385, 4071) 1
(18385, 4072) 1
(18385, 4073) 1
(18385, 4074) 1
(18385, 4075) 1
(18385, 4076) 1
(18385, 4077) 1
(18385, 4078) 1
(18385, 4079) 1
(18385, 4080) 1
(18385, 4081) 1
: :
(18403, 18360) 1
(18403, 18361) 1
(18403, 18362) 1
(18403, 18363) 1
(18403, 18364) 1
(18403, 18365) 1
(18403, 18366) 1
(18403, 18367) 1
(18403, 18368) 1
(18403, 18369) 1
(18403, 18370) 1
(18403, 18371) 1
(18403, 18372) 1
(18403, 18373) 1
(18404, 18374) 1
(18404, 18375) 1
(18404, 18376) 1
(18404, 18377) 1
(18404, 18378) 1
(18404, 18379) 1
(18404, 18380) 1
(18404, 18381) 1
(18404, 18382) 1
(18404, 18383) 1
(18404, 18384) 1
shape (18405, 18405, 5)