Home python How to make a two-dimensional array?

How to make a two-dimensional array?




I have an array:

b = ['Hi!', 'My Name Is Ivan.', 'I am Beginner Programier ... ']

From it I want to do this:

b = [['Hi!'], ['My Name IS Ivan.'], ['I am Beginner Programier ... ']]

That is, an array, where each element is an array.

Answer 1, Authority 100%

Vanilla Python:

b = list (lambda x: [x], b))


b = [[x] for x in b]


import numpy as np # pip install numpy
B = np.asarray (b) .reshape (-1, 1)


in [36]: b
Out [36]:
Array ([['Hi!'],
    ['My Name Is Ivan.'],
    ['I am Beginner Programier ...']], dtype = '& lt; u27')
In [37]: B.shape
Out [37]: (3, 1)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions