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

```
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.

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

## What is the difference between flatten and ravel functions in numpy? 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.

## What is the difference between flatten and ravel functions in numpy? 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 What is the difference between flatten and ravel functions in numpy?, 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 What is the difference between flatten and ravel functions in numpy?
- Deutsch What is the difference between flatten and ravel functions in numpy?
- Français What is the difference between flatten and ravel functions in numpy?
- Español What is the difference between flatten and ravel functions in numpy?
- Türk What is the difference between flatten and ravel functions in numpy?
- Русский What is the difference between flatten and ravel functions in numpy?
- Português What is the difference between flatten and ravel functions in numpy?
- Polski What is the difference between flatten and ravel functions in numpy?
- Nederlandse What is the difference between flatten and ravel functions in numpy?
- 中文 What is the difference between flatten and ravel functions in numpy?
- 한국어 What is the difference between flatten and ravel functions in numpy?
- 日本語 What is the difference between flatten and ravel functions in numpy?
- हिन्दी What is the difference between flatten and ravel functions in numpy?

Munchen | 2022-11-26

Simply put and clear. Thank you for sharing. What is the difference between flatten and ravel functions in numpy? and other issues with ravel was always my weak point 😁. I just hope that will not emerge anymore

Prague | 2022-11-26

Simply put and clear. Thank you for sharing. What is the difference between flatten and ravel functions in numpy? and other issues with ravel was always my weak point 😁. Checked yesterday, it works!

Paris | 2022-11-26

I was preparing for my coding interview, thanks for clarifying this - What is the difference between flatten and ravel functions in numpy? in Python is not the simplest one. Checked yesterday, it works!