Python numpy展平-如何打印输出
我需要把数组变成向量。这是我的密码Python numpy展平-如何打印输出,python,numpy,flatten,Python,Numpy,Flatten,我需要把数组变成向量。这是我的密码 from numpy import * s1 = random.poisson(5,100).flatten print(s1) 输出 <built-in method flatten of numpy.ndarray object at 0x0508DE80> 我做错了什么?你忘了括号。您需要调用该方法。如果省略括号,则只能获得该方法的句柄: s1 = random.poisson(5,100).flatten() 但是,为了完整性,您
from numpy import *
s1 = random.poisson(5,100).flatten
print(s1)
输出
<built-in method flatten of numpy.ndarray object at 0x0508DE80>
我做错了什么?你忘了括号。您需要调用该方法。如果省略括号,则只能获得该方法的句柄:
s1 = random.poisson(5,100).flatten()
但是,为了完整性,您可以这样做。。。但对于代码可读性,可能不应该:
s1 = random.poisson(5,100).flatten
print(s1()) # <-- Calling the function
s1=random.poisson(5100).展平
print(s1())#展平
是一种方法,称之为。哇!我不知道掌握这种方法这么容易。谢谢大家!@user1700890-不用担心:)