Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a numpy array of size (100, 1) and (100,)?

Tags:

python

numpy

I have two variables coming from diffrent functions and the first one a is:

<class 'numpy.ndarray'>
(100,)

while the other one b is:

<class 'numpy.ndarray'>
(100, 1)

If I try to correlate them via:

from scipy.stats import pearsonr
p, r= pearsonr(a, b)

I get:

    r = max(min(r, 1.0), -1.0)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

My questions are:

  1. What is the difference between a and b?
  2. How do I fix this?
like image 973
lordy Avatar asked Jan 31 '26 06:01

lordy


1 Answers

(100,1) is 2d array of rows of length 1 like = [[1],[2],[3],[4]] and second one is 1d array [1, 2, 3, 4 ]

a1 = np.array([[1],[2],[3],[4]])
a2 = np.array([1, 2, 3, 4 ])
like image 137
user8426627 Avatar answered Feb 01 '26 18:02

user8426627



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!