I have an array of coordinates:
points = [x,y]
with the (numpy) dimensions/shape: (18, 1, 2)
In matlab, to initialize an array of ones to index these points with '3', I could do this:
A = ones(size(points,1),1)*3'
How could I do this using python3 and numpy in the fastest possible way?
def time_compare(self):
loops = 100000000
start = time.time()
for i in range(loops):
self.value_map.shape[0]
self.value_map[0].shape[0]
self.value_map[0][0].shape[0]
self.value_map[0][0][0].shape[0]
end = time.time()
timed = (end - start)
print("shape={}".format(timed))
start = time.time()
for i in range(loops):
len(self.value_map)
len(self.value_map[0])
len(self.value_map[0][0])
len(self.value_map[0][0][0])
end = time.time()
timed = (end - start)
print("len={}".format(timed))
shape=102.26551818847656
len=87.99720764160156
len is faster than shape
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With