From d85c270ce64b98ce668d3dffb4df9df7e23bb9d5 Mon Sep 17 00:00:00 2001 From: David Rotermund <54365609+davrot@users.noreply.github.com> Date: Sat, 30 Dec 2023 01:46:53 +0100 Subject: [PATCH] Update README.md Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com> --- numpy/convert_into_ndarray/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/numpy/convert_into_ndarray/README.md b/numpy/convert_into_ndarray/README.md index 75ef6c7..790166c 100644 --- a/numpy/convert_into_ndarray/README.md +++ b/numpy/convert_into_ndarray/README.md @@ -21,8 +21,30 @@ numpy.asarray(a, dtype=None, order=None, *, like=None) > Convert the input to an array. +```python +import numpy as np +a_list = [[1, 2], [3, 4]] +a_np = np.asarray(a_list) + +w = np.asarray(1) + +print(w.sum()) # -> 1 +print(a_np.sum()) # -> 10 +print(a_np > 2) + +print(1.sum()) # SyntaxError: invalid decimal literal +print(a_list.sum()) # AttributeError: 'list' object has no attribute 'sum' +print(a_list > 2) # TypeError: '>' not supported between instances of 'list' and 'int' +``` + +Output: + +```python +[[False False] + [ True True]] +``` ## [numpy.fromiter](https://numpy.org/doc/stable/reference/generated/numpy.fromiter.html)