[英]A 2-d numpy ndarray showing 1-d shape
I am getting a numpy array from the following function我从以下 function 得到一个 numpy 数组
def get_word_vec_norm(post):
doc = nlp(post)
word_vec = []
index = 1
for token in doc:
word_vec.append(token.vector_norm)
index = index + 1
if index>2:
break
# return word_vec
return np.asarray(word_vec)
after the calling this function在调用这个 function
X = data['cleaned_post'].apply(get_word_vec_norm)
Now, I was expecting shape of X is (18,2)
but it showing (18, 1)
as shown in following image.现在,我期待 X 的形状是
(18,2)
但它显示(18, 1)
如下图所示。
I think I have done something wrong somewhere.我想我在某个地方做错了什么。 Would anyone please correct me.
有人请纠正我。 I would be thankful.
我会很感激的。 thank you.
谢谢你。
If you upload the matrix X
or the DataFrame
, I could provide a more details answer.如果您上传矩阵
X
或DataFrame
,我可以提供更详细的答案。
In the function you use word_vec.append(token.vector_norm)
so you append elements into a list.在 function 中,您使用
word_vec.append(token.vector_norm)
以便将 append 元素放入列表中。
and then you do: np.asarray(word_vec)
, ie you convert the list into numpy array然后你做:
np.asarray(word_vec)
,即将列表转换为 numpy 数组
This lead to the observed output.这导致观察到的 output。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.