argmax

Pandas: Resample dataframe column, get discrete feature that corresponds to max value

与世无争的帅哥 提交于 2020-01-01 16:42:28
问题 Sample data: import pandas as pd import numpy as np import datetime data = {'value': [1,2,4,3], 'names': ['joe', 'bob', 'joe', 'bob']} start, end = datetime.datetime(2015, 1, 1), datetime.datetime(2015, 1, 4) test = pd.DataFrame(data=data, index=pd.DatetimeIndex(start=start, end=end, freq="D"), columns=["value", "names"]) gives: value names 2015-01-01 1 joe 2015-01-02 2 bob 2015-01-03 4 joe 2015-01-04 3 bob I want to resample by '2D' and get the max value, something like: df.resample('2D')

tensorflow之分类学习

╄→гoц情女王★ 提交于 2019-12-27 10:52:54
写在前面的话 MNIST教程是tensorflow中文社区的第一课,例程即训练一个 手写数字识别 模型: http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html 参考视频: https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/5-01-classifier/ MNIST编程 代码全文 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets('MNIST_data',one_hot = True) def add_layer(inputs, in_size, out_size, activation_function=None): Weights = tf.Variable(tf.random_normal([in_size, out_size])) biases = tf.Variable(tf.zeros([1, out_size]) + 0.1) Wx_plus_b = tf.matmul(inputs, Weights) + biases if

tensorflow中手写识别笔记

微笑、不失礼 提交于 2019-12-24 13:56:58
教程链接: https://www.w3cschool.cn/tensorflow_python/tensorflow_python-c1ov28so.html tensorflow 常用的函数: # 导入tensorflow,使用tf代替 import tensorflow as tf # 计算x,和w的乘积,这里计算x矩阵和w矩阵的乘积 tf.matmul(x, w) # 先计算labels和logits的交叉熵(区别),在对结果进行归一化处理, softmax参考 tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y) # 然后求交叉熵的平均值 cross_entrony = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y)) # 以梯度下降法,0.5的幅度,减小交叉熵 tf.train.GradientDescentOptimizer(0.5).minimize(cross_entrony) # 初始化变量(tf,Variable()) tf.global_variables_initializer().run() # 获取一行最大值的索引 tf.argmax(y, 1) # 比较a和b对应位置是否是相同的

Extracting the max, min or std from a DF for a particular column in pandas

Deadly 提交于 2019-12-24 10:37:00
问题 I have a df with columns X1, Y1, Z3. df.describe shows the stats for each column I would like to extract the min, max and std for say column Z3. df[df.z3].idxmax() doesn't seem to work 回答1: Demo: In [7]: df = pd.DataFrame(np.random.rand(10, 3), columns=['X1','Y1','Z3']) In [8]: df Out[8]: X1 Y1 Z3 0 0.258116 0.667943 0.954830 1 0.584975 0.546284 0.045745 2 0.698974 0.409223 0.307409 3 0.073166 0.356393 0.722233 4 0.339093 0.146043 0.614686 5 0.624361 0.062805 0.574546 6 0.886631 0.217291 0

Tensorflow中的tf.argmax()函数

◇◆丶佛笑我妖孽 提交于 2019-12-23 13:43:29
转载请注明出处: http://www.cnblogs.com/willnote/p/6758953.html 官方API定义 tf.argmax(input, axis=None, name=None, dimension=None) Returns the index with the largest value across axes of a tensor. Args: input : A Tensor. Must be one of the following types: float32, float64, int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half. axis : A Tensor. Must be one of the following types: int32, int64. int32, 0 <= axis < rank(input). Describes which axis of the input Tensor to reduce across. For vectors, use axis = 0. name : A name for the operation (optional). Returns: A

pandas idxmax: return all rows in case of ties

故事扮演 提交于 2019-12-23 12:26:11
问题 I am working with a dataframe where I have weight each row by its probability. Now, I want to select the row with the highest probability and I am using pandas idxmax() to do so, however when there are ties, it just returns the first row among the ones that tie. In my case, I want to get all the rows that tie . Furthermore, I am doing this as part of a research project where I am processing millions a dataframes like the one below, so keeping it fast is an issue. Example: My data looks like

cumulative argmax of a numpy array

让人想犯罪 __ 提交于 2019-12-22 10:52:07
问题 Consider the array a np.random.seed([3,1415]) a = np.random.randint(0, 10, (10, 2)) a array([[0, 2], [7, 3], [8, 7], [0, 6], [8, 6], [0, 2], [0, 4], [9, 7], [3, 2], [4, 3]]) What is a vectorized way to get the cumulative argmax? array([[0, 0], <-- both start off as max position [1, 1], <-- 7 > 0 so 1st col = 1, 3 > 2 2nd col = 1 [2, 2], <-- 8 > 7 1st col = 2, 7 > 3 2nd col = 2 [2, 2], <-- 0 < 8 1st col stays the same, 6 < 7 2nd col stays the same [2, 2], [2, 2], [2, 2], [7, 2], <-- 9 is new

tf.argmax 与 tf.arg_max

柔情痞子 提交于 2019-12-19 00:18:13
tf.argmax 与 tf.arg_max 用法相同,下面介绍 tf.argmax 用法 tf.argmax def argmax(input, axis=None, name=None, dimension=None, output_type=dtypes.int64) numpy.argmax(a, axis=None, out=None) 返回沿轴axis最大值的索引。 Parameters: input: array_like,数组 axis : int, 可选,默认情况下,索引的是平铺的数组,否则沿指定的轴。 out : array, 可选 如果提供,结果以合适的形状和类型被插入到此数组中。 Returns: index_array : ndarray of ints 索引数组。它具有与a.shape相同的形状,其中axis被移除。 tf.argmax() 与 numpy.argmax() 方法的用法是一致的 axis = 0 的时候返回每一列最大值的位置索引 axis = 1 的时候返回每一行最大值的位置索引 axis = 2、3、4 ...,即为多维张量时,同理推断 例子 >>> a = np.arange(6).reshape(2,3) >>> a array([[0, 1, 2], [3, 4, 5]]) >>> np.argmax(a) 5 >>> np

Scala/Spark dataframes: find the column name corresponding to the max

孤人 提交于 2019-12-17 19:51:26
问题 In Scala/Spark, having a dataframe: val dfIn = sqlContext.createDataFrame(Seq( ("r0", 0, 2, 3), ("r1", 1, 0, 0), ("r2", 0, 2, 2))).toDF("id", "c0", "c1", "c2") I would like to compute a new column maxCol holding the name of the column corresponding to the max value (for each row). With this example, the output should be: +---+---+---+---+------+ | id| c0| c1| c2|maxCol| +---+---+---+---+------+ | r0| 0| 2| 3| c2| | r1| 1| 0| 0| c0| | r2| 0| 2| 2| c1| +---+---+---+---+------+ Actually the

numpy之argmin(), argmax(), argsort()

浪子不回头ぞ 提交于 2019-12-14 05:44:06
argmin(), argmax(), argsort() 以及利用argsort()函数实现数组的升序、降序 import numpy as np a = np . array ( [ 11 , 3 , 5 , 18 ] ) x = np . argmax ( a ) print ( x ) # 返回数组中最大元素的索引值: 3 y = np . argmin ( a ) print ( y ) #返回的是数组中最小元素的索引值: 1 z = np . argsort ( a ) print ( z ) #返回的是将数组a中的元素按升序排列后对应元素的索引值数组: 【1,2,0,3】 w = np . argsort ( - a ) print ( w ) #返回的是将数组a中的元素按降序排列后对应元素的索引值数组: 【3,0,2,1】 a_ascend = a [ z ] print ( a_ascend ) #返回a按升序排列后的数组 : 【3,5,11,18】 a_descend = a [ z [ : : - 1 ] ] print ( a_descend ) #返回a按降序排列后的数组: 【18,11,5,3】 python中argsort()函数的用法 来源: CSDN 作者: 五取蕴_41121879 链接: https://blog.csdn.net/qq