Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Slicing using vectors
#2
Try this:

import numpy as np
n = 100
m = 2
A = np.array(np.random.randint(66, size=(n,m), dtype=np.int32))
i = np.array(np.random.randint(n-4, size=int(0.5*n), dtype=np.int32))
j = i + 4*np.ones(int(0.5*n), dtype=np.int32)
print(i)
print(j)
print(i.shape)
print(j.shape)
extract1_A = np.array(A[i,:])
extract2_A = np.array([ A[x:x+4,:] for x in i])
extract3_A = np.array([ A[x:y,:] for x in i for y in j])
print (extract1_A.shape)
print (extract2_A.shape)
print (extract3_A.shape)
Smile wish everyone happy coding Smile
Reply


Messages In This Thread
Slicing using vectors - by paul18fr - Nov-14-2019, 10:06 AM
RE: Slicing using vectors - by schuler - Nov-15-2019, 12:15 AM
RE: Slicing using vectors - by paul18fr - Nov-15-2019, 11:00 AM
RE: Slicing using vectors - by micseydel - Nov-16-2019, 12:00 AM
RE: Slicing using vectors - by paul18fr - Nov-16-2019, 10:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Scaling of mapped vectors? sricha1217 1 2,375 Apr-10-2018, 10:26 AM
Last Post: sricha1217
  Statistics: Two histograms based on word frequency vectors fancy_panther 2 4,787 Mar-27-2017, 01:18 AM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020