1
import numpy as np
array1 = np.array([[0, 1, 7, 9], [1, 2, 2, 2, 3]])
print(array1)
b = np.array([[10,20,34],[54,43,75]])
print(b)
arr = np.array([[0,1,7,9,12,18],[19,20,24,26,30]])
print(arr)
print(type(array1))
print(type(b))
print(type(arr))

Output - The first and third array give a different output even though they are created similarly

[list([0, 1, 7, 9]) list([1, 2, 2, 2, 3])]

[[10 20 34]
 [54 43 75]]

[list([0, 1, 7, 9, 12, 18]) list([19, 20, 24, 26, 30])]

<class 'numpy.ndarray'>

<class 'numpy.ndarray'>

<class 'numpy.ndarray'>
ObjectJosh
  • 601
  • 3
  • 14
Faraz
  • 45
  • 1
  • 7

1 Answers1

0

There are discrepancies between 2d arrays 1 and 3 vs. array 2. Notice the difference in list sizes. 2d arrays 1 and 3 are not rectangular, whereas array 2 is. If you are seeing a VisibleDeprecationWarning, you can get rid of this error by adding dtype=object to the non-rectangular 2d arrays. See provided comments below.

More on numpy arrays

More on VisibleDeprecationWarning

import numpy as np
# ARRAY 1
# 4 items, 5 items
array1 = np.array([[0, 1, 7, 9], [1, 2, 2, 2, 3]], dtype=object)
print(array1)

# ARRAY 2
# 3 items, 3 items
b = np.array([[10,20,34],[54,43,75]])
print(b)

# ARRAY 3
# 6 items, 5 items
arr = np.array([[0,1,7,9,12,18],[19,20,24,26,30]], dtype=object)
print(arr)
ObjectJosh
  • 601
  • 3
  • 14