Slice an array into multiple arrays - Python

0 votes

I have an array that I would like to slice into multiple arrays in the form of:

M = [1,2,3         
     4,5,6
     7,8,9]
 to [ [1],[2]....[9] ]  (List of arrays)
May 29, 2019 in Python by Meena
764 views

1 answer to this question.

0 votes

can use numpy.reshape. 

In your case, pass 1 as 2nd dimension, and let the method infer the first dimension by passing -1:

M = [1, 2, 3,
     4, 5, 6,
     7, 8, 9]

np.reshape(M, (-1, 1))
answered May 29, 2019 by Alia

Related Questions In Python

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Is arr.__len__() the preferred way to get the length of an array in Python?

my_list = [1,2,3,4,5,6,7] len(my_list) # 7 The same works for ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 13,300 points
943 views
0 votes
1 answer

How can I turn an input date into a readable string in Python?

The datetime class has a method strftime. strftime() ...READ MORE

answered Dec 11, 2018 in Python by aryya
• 7,460 points
702 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,423 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,043 views
+4 votes
7 answers
0 votes
1 answer

I'm using Python 2.7 to convert an XML response (from a REST call to Atlassian Fisheye) into an HTML table.

You don't have a template matching tabularQueryResult in your ...READ MORE

answered Oct 4, 2018 in Python by Priyaj
• 58,020 points
1,437 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP