👻 *Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!*

I have a list in python and I want to convert it to an array to be able to use `ravel()`

function.

👻 *Read also: what is the best laptop for engineering students?*

## List to array conversion to use ravel() function ravel: Questions

What is the difference between flatten and ravel functions in numpy?

2 answers

```
import numpy as np
y = np.array(((1,2,3),(4,5,6),(7,8,9)))
OUTPUT:
print(y.flatten())
[1 2 3 4 5 6 7 8 9]
print(y.ravel())
[1 2 3 4 5 6 7 8 9]
```

Both function return the same list. Then what is the need of two different functions performing same job.

Answer #1

The current API is that:

`flatten`

always returns a copy.`ravel`

returns a view of the original array whenever possible. This isn"t visible in the printed output, but if you modify the array returned by ravel, it may modify the entries in the original array. If you modify the entries in an array returned from flatten this will never happen. ravel will often be faster since no memory is copied, but you have to be more careful about modifying the array it returns.`reshape((-1,))`

gets a view whenever the strides of the array allow it even if that means you don"t always get a contiguous array.

## List to array conversion to use ravel() function ravel: Questions

List to array conversion to use ravel() function

2 answers

I have a list in python and I want to convert it to an array to be able to use `ravel()`

function.

Answer #1

Use `numpy.asarray`

:

```
import numpy as np
myarray = np.asarray(mylist)
```

We hope this article has helped you to resolve the problem. Apart from List to array conversion to use ravel() function, check other ravel-related topics.

Want to excel in Python? See our review of the best Python online courses 2022. If you are interested in Data Science, check also how to learn programming in R.

By the way, this material is also available in other languages:

- Italiano List to array conversion to use ravel() function
- Deutsch List to array conversion to use ravel() function
- Français List to array conversion to use ravel() function
- Español List to array conversion to use ravel() function
- Türk List to array conversion to use ravel() function
- Русский List to array conversion to use ravel() function
- Português List to array conversion to use ravel() function
- Polski List to array conversion to use ravel() function
- Nederlandse List to array conversion to use ravel() function
- 中文 List to array conversion to use ravel() function
- 한국어 List to array conversion to use ravel() function
- 日本語 List to array conversion to use ravel() function
- हिन्दी List to array conversion to use ravel() function

Prague | 2022-11-30

Maybe there are another answers? What List to array conversion to use ravel() function exactly means?. Will get back tomorrow with feedback

Shanghai | 2022-11-30

I was preparing for my coding interview, thanks for clarifying this - List to array conversion to use ravel() function in Python is not the simplest one. Will get back tomorrow with feedback

Rome | 2022-11-30

Thanks for explaining! I was stuck with List to array conversion to use ravel() function for some hours, finally got it done 🤗. I am just not quite sure it is the best method