今天用phoenix报如下错误:

主要原因:

  hbase的表中某字段类型是array,phoenix目前不支持此类型

解决方法:

复制替换phoenix包的cursor文件

  1. # Copyright 2015 Lukas Lalinsky
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14.  
  15. import logging,re
  16. import collections
  17. from phoenixdb.types import TypeHelper
  18. from phoenixdb.errors import OperationalError, NotSupportedError, ProgrammingError, InternalError
  19. from phoenixdb.calcite import common_pb2
  20.  
  21. __all__ = ['Cursor', 'ColumnDescription', 'DictCursor']
  22.  
  23. logger = logging.getLogger(__name__)
  24.  
  25. # TODO see note in Cursor.rowcount()
  26. MAX_INT = 2 ** 64 - 1
  27.  
  28. ColumnDescription = collections.namedtuple('ColumnDescription', 'name type_code display_size internal_size precision scale null_ok')
  29. """Named tuple for representing results from :attr:`Cursor.description`."""
  30.  
  31. class Cursor(object):
  32. """Database cursor for executing queries and iterating over results.
  33.  
  34. You should not construct this object manually, use :meth:`Connection.cursor() <phoenixdb.connection.Connection.cursor>` instead.
  35. """
  36.  
  37. arraysize = 1
  38. """
  39. Read/write attribute specifying the number of rows to fetch
  40. at a time with :meth:`fetchmany`. It defaults to 1 meaning to
  41. fetch a single row at a time.
  42. """
  43.  
  44. itersize = 2000
  45. """
  46. Read/write attribute specifying the number of rows to fetch
  47. from the backend at each network roundtrip during iteration
  48. on the cursor. The default is 2000.
  49. """
  50.  
  51. def __init__(self, connection, id=None):
  52. self._connection = connection
  53. self._id = id
  54. self._signature = None
  55. self._column_data_types = []
  56. self._frame = None
  57. self._pos = None
  58. self._closed = False
  59. self.arraysize = self.__class__.arraysize
  60. self.itersize = self.__class__.itersize
  61. self._updatecount = -1
  62.  
  63. def __del__(self):
  64. if not self._connection._closed and not self._closed:
  65. self.close()
  66.  
  67. def __enter__(self):
  68. return self
  69.  
  70. def __exit__(self, exc_type, exc_value, traceback):
  71. if not self._closed:
  72. self.close()
  73.  
  74. def __iter__(self):
  75. return self
  76.  
  77. def __next__(self):
  78. row = self.fetchone()
  79. if row is None:
  80. raise StopIteration
  81. return row
  82.  
  83. next = __next__
  84.  
  85. def close(self):
  86. """Closes the cursor.
  87. No further operations are allowed once the cursor is closed.
  88.  
  89. If the cursor is used in a ``with`` statement, this method will
  90. be automatically called at the end of the ``with`` block.
  91. """
  92. if self._closed:
  93. raise ProgrammingError('the cursor is already closed')
  94. if self._id is not None:
  95. self._connection._client.close_statement(self._connection._id, self._id)
  96. self._id = None
  97. self._signature = None
  98. self._column_data_types = []
  99. self._frame = None
  100. self._pos = None
  101. self._closed = True
  102.  
  103. @property
  104. def closed(self):
  105. """Read-only attribute specifying if the cursor is closed or not."""
  106. return self._closed
  107.  
  108. @property
  109. def description(self):
  110. if self._signature is None:
  111. return None
  112. description = []
  113. for column in self._signature.columns:
  114. description.append(ColumnDescription(
  115. column.column_name,
  116. column.type.name,
  117. column.display_size,
  118. None,
  119. column.precision,
  120. column.scale,
  121. None if column.nullable == 2 else bool(column.nullable),
  122. ))
  123. return description
  124.  
  125. def _set_id(self, id):
  126. if self._id is not None and self._id != id:
  127. self._connection._client.close_statement(self._connection._id, self._id)
  128. self._id = id
  129.  
  130. def _set_signature(self, signature):
  131. self._signature = signature
  132. self._column_data_types = []
  133. self._parameter_data_types = []
  134. if signature is None:
  135. return
  136.  
  137. for column in signature.columns:
  138. dtype = TypeHelper.from_class(column.column_class_name)
  139. self._column_data_types.append(dtype)
  140.  
  141. for parameter in signature.parameters:
  142. dtype = TypeHelper.from_class(parameter.class_name)
  143. self._parameter_data_types.append(dtype)
  144.  
  145. def _set_frame(self, frame):
  146. self._frame = frame
  147. self._pos = None
  148.  
  149. if frame is not None:
  150. if frame.rows:
  151. self._pos = 0
  152. elif not frame.done:
  153. raise InternalError('got an empty frame, but the statement is not done yet')
  154.  
  155. def _fetch_next_frame(self):
  156. offset = self._frame.offset + len(self._frame.rows)
  157. frame = self._connection._client.fetch(self._connection._id, self._id,
  158. offset=offset, frame_max_size=self.itersize)
  159. self._set_frame(frame)
  160.  
  161. def _process_results(self, results):
  162. if results:
  163. result = results[0]
  164. if result.own_statement:
  165. self._set_id(result.statement_id)
  166. self._set_signature(result.signature if result.HasField('signature') else None)
  167. self._set_frame(result.first_frame if result.HasField('first_frame') else None)
  168. self._updatecount = result.update_count
  169.  
  170. def _transform_parameters(self, parameters):
  171. typed_parameters = []
  172. for value, data_type in zip(parameters, self._parameter_data_types):
  173. field_name, rep, mutate_to, cast_from = data_type
  174. typed_value = common_pb2.TypedValue()
  175.  
  176. if value is None:
  177. typed_value.null = True
  178. typed_value.type = common_pb2.NULL
  179. else:
  180. typed_value.null = False
  181.  
  182. # use the mutator function
  183. if mutate_to is not None:
  184. value = mutate_to(value)
  185.  
  186. typed_value.type = rep
  187. setattr(typed_value, field_name, value)
  188.  
  189. typed_parameters.append(typed_value)
  190. return typed_parameters
  191.  
  192. def execute(self, operation, parameters=None):
  193. if self._closed:
  194. raise ProgrammingError('the cursor is already closed')
  195. self._updatecount = -1
  196. self._set_frame(None)
  197. if parameters is None:
  198. if self._id is None:
  199. self._set_id(self._connection._client.create_statement(self._connection._id))
  200. results = self._connection._client.prepare_and_execute(self._connection._id, self._id,
  201. operation, first_frame_max_size=self.itersize)
  202. self._process_results(results)
  203. else:
  204. statement = self._connection._client.prepare(self._connection._id,
  205. operation)
  206. self._set_id(statement.id)
  207. self._set_signature(statement.signature)
  208.  
  209. results = self._connection._client.execute(self._connection._id, self._id,
  210. statement.signature, self._transform_parameters(parameters),
  211. first_frame_max_size=self.itersize)
  212. self._process_results(results)
  213.  
  214. def executemany(self, operation, seq_of_parameters):
  215. if self._closed:
  216. raise ProgrammingError('the cursor is already closed')
  217. self._updatecount = -1
  218. self._set_frame(None)
  219. statement = self._connection._client.prepare(self._connection._id,
  220. operation, max_rows_total=0)
  221. self._set_id(statement.id)
  222. self._set_signature(statement.signature)
  223. for parameters in seq_of_parameters:
  224. self._connection._client.execute(self._connection._id, self._id,
  225. statement.signature, self._transform_parameters(parameters),
  226. first_frame_max_size=0)
  227.  
  228. def _transform_row(self, row):
  229. """Transforms a Row into Python values.
  230.  
  231. :param row:
  232. A ``common_pb2.Row`` object.
  233.  
  234. :returns:
  235. A list of values casted into the correct Python types.
  236.  
  237. :raises:
  238. NotImplementedError
  239. """
  240. tmp_row = []
  241.  
  242. for i, column in enumerate(row.value):
  243. if column.has_array_value:
  244. # 修改的地方===============
  245. column_value = str(column.value)
  246. if 'INTEGER' in column_value:
  247. pattern = '(\d+)'
  248. elif 'string_value' in column_value:
  249. pattern = 'string_value: "(.+)"'
  250. else:
  251. raise NotImplementedError('array types are not supported')
  252. value = re.findall(pattern, str(column.value))
  253. tmp_row.append(value)
  254. # =========================
  255. elif column.scalar_value.null:
  256. tmp_row.append(None)
  257. else:
  258. field_name, rep, mutate_to, cast_from = self._column_data_types[i]
  259.  
  260. # get the value from the field_name
  261. value = getattr(column.scalar_value, field_name)
  262.  
  263. # cast the value
  264. if cast_from is not None:
  265. value = cast_from(value)
  266.  
  267. tmp_row.append(value)
  268. return tmp_row
  269.  
  270. def fetchone(self):
  271. if self._frame is None:
  272. raise ProgrammingError('no select statement was executed')
  273. if self._pos is None:
  274. return None
  275. rows = self._frame.rows
  276. row = self._transform_row(rows[self._pos])
  277. self._pos += 1
  278. if self._pos >= len(rows):
  279. self._pos = None
  280. if not self._frame.done:
  281. self._fetch_next_frame()
  282. return row
  283.  
  284. def fetchmany(self, size=None):
  285. if size is None:
  286. size = self.arraysize
  287. rows = []
  288. while size > 0:
  289. row = self.fetchone()
  290. if row is None:
  291. break
  292. rows.append(row)
  293. size -= 1
  294. return rows
  295.  
  296. def fetchall(self):
  297. rows = []
  298. while True:
  299. row = self.fetchone()
  300. if row is None:
  301. break
  302. rows.append(row)
  303. return rows
  304.  
  305. def setinputsizes(self, sizes):
  306. pass
  307.  
  308. def setoutputsize(self, size, column=None):
  309. pass
  310.  
  311. @property
  312. def connection(self):
  313. """Read-only attribute providing access to the :class:`Connection <phoenixdb.connection.Connection>` object this cursor was created from."""
  314. return self._connection
  315.  
  316. @property
  317. def rowcount(self):
  318. """Read-only attribute specifying the number of rows affected by
  319. the last executed DML statement or -1 if the number cannot be
  320. determined. Note that this will always be set to -1 for select
  321. queries."""
  322. # TODO instead of -1, this ends up being set to Integer.MAX_VALUE
  323. if self._updatecount == MAX_INT:
  324. return -1
  325. return self._updatecount
  326.  
  327. @property
  328. def rownumber(self):
  329. """Read-only attribute providing the current 0-based index of the
  330. cursor in the result set or ``None`` if the index cannot be
  331. determined.
  332.  
  333. The index can be seen as index of the cursor in a sequence
  334. (the result set). The next fetch operation will fetch the
  335. row indexed by :attr:`rownumber` in that sequence.
  336. """
  337. if self._frame is not None and self._pos is not None:
  338. return self._frame.offset + self._pos
  339. return self._pos
  340.  
  341. class DictCursor(Cursor):
  342. """A cursor which returns results as a dictionary"""
  343.  
  344. def _transform_row(self, row):
  345. row = super(DictCursor, self)._transform_row(row)
  346. d = {}
  347. for ind, val in enumerate(row):
  348. d[self._signature.columns[ind].column_name] = val
  349. return d

复制替换phoenix包下的types.py文件

  1. # Copyright 2015 Lukas Lalinsky
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14.  
  15. import sys
  16. import time
  17. import datetime
  18. from decimal import Decimal
  19. from phoenixdb.calcite import common_pb2
  20.  
  21. __all__ = [
  22. 'Date', 'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks', 'TimestampFromTicks',
  23. 'Binary', 'STRING', 'BINARY', 'NUMBER', 'DATETIME', 'ROWID', 'BOOLEAN',
  24. 'JAVA_CLASSES', 'JAVA_CLASSES_MAP', 'TypeHelper', 'PhoenixArray'
  25. ]
  26.  
  27. def PhoenixArray(value):
  28. print(value)
  29. return value
  30. def Date(year, month, day):
  31. """Constructs an object holding a date value."""
  32. return datetime.date(year, month, day)
  33.  
  34. def Time(hour, minute, second):
  35. """Constructs an object holding a time value."""
  36. return datetime.time(hour, minute, second)
  37.  
  38. def Timestamp(year, month, day, hour, minute, second):
  39. """Constructs an object holding a datetime/timestamp value."""
  40. return datetime.datetime(year, month, day, hour, minute, second)
  41.  
  42. def DateFromTicks(ticks):
  43. """Constructs an object holding a date value from the given UNIX timestamp."""
  44. return Date(*time.localtime(ticks)[:3])
  45.  
  46. def TimeFromTicks(ticks):
  47. """Constructs an object holding a time value from the given UNIX timestamp."""
  48. return Time(*time.localtime(ticks)[3:6])
  49.  
  50. def TimestampFromTicks(ticks):
  51. """Constructs an object holding a datetime/timestamp value from the given UNIX timestamp."""
  52. return Timestamp(*time.localtime(ticks)[:6])
  53.  
  54. def Binary(value):
  55. """Constructs an object capable of holding a binary (long) string value."""
  56. return bytes(value)
  57.  
  58. def time_from_java_sql_time(n):
  59. dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(milliseconds=n)
  60. return dt.time()
  61.  
  62. def time_to_java_sql_time(t):
  63. return ((t.hour * 60 + t.minute) * 60 + t.second) * 1000 + t.microsecond // 1000
  64.  
  65. def date_from_java_sql_date(n):
  66. return datetime.date(1970, 1, 1) + datetime.timedelta(days=n)
  67.  
  68. def date_to_java_sql_date(d):
  69. if isinstance(d, datetime.datetime):
  70. d = d.date()
  71. td = d - datetime.date(1970, 1, 1)
  72. return td.days
  73.  
  74. def datetime_from_java_sql_timestamp(n):
  75. return datetime.datetime(1970, 1, 1) + datetime.timedelta(milliseconds=n)
  76.  
  77. def datetime_to_java_sql_timestamp(d):
  78. td = d - datetime.datetime(1970, 1, 1)
  79. return td.microseconds // 1000 + (td.seconds + td.days * 24 * 3600) * 1000
  80.  
  81. class ColumnType(object):
  82.  
  83. def __init__(self, eq_types):
  84. self.eq_types = tuple(eq_types)
  85. self.eq_types_set = set(eq_types)
  86.  
  87. def __eq__(self, other):
  88. return other in self.eq_types_set
  89.  
  90. def __cmp__(self, other):
  91. if other in self.eq_types_set:
  92. return 0
  93. if other < self.eq_types:
  94. return 1
  95. else:
  96. return -1
  97.  
  98. STRING = ColumnType(['VARCHAR', 'CHAR'])
  99. """Type object that can be used to describe string-based columns."""
  100.  
  101. BINARY = ColumnType(['BINARY', 'VARBINARY'])
  102. """Type object that can be used to describe (long) binary columns."""
  103.  
  104. NUMBER = ColumnType(['INTEGER', 'UNSIGNED_INT', 'BIGINT', 'UNSIGNED_LONG', 'TINYINT', 'UNSIGNED_TINYINT', 'SMALLINT', 'UNSIGNED_SMALLINT', 'FLOAT', 'UNSIGNED_FLOAT', 'DOUBLE', 'UNSIGNED_DOUBLE', 'DECIMAL'])
  105. """Type object that can be used to describe numeric columns."""
  106.  
  107. DATETIME = ColumnType(['TIME', 'DATE', 'TIMESTAMP', 'UNSIGNED_TIME', 'UNSIGNED_DATE', 'UNSIGNED_TIMESTAMP'])
  108. """Type object that can be used to describe date/time columns."""
  109.  
  110. ROWID = ColumnType([])
  111. """Only implemented for DB API 2.0 compatibility, not used."""
  112.  
  113. BOOLEAN = ColumnType(['BOOLEAN'])
  114. """Type object that can be used to describe boolean columns. This is a phoenixdb-specific extension."""
  115.  
  116. # XXX ARRAY
  117.  
  118. JAVA_CLASSES = {
  119. 'bool_value': [
  120. ('java.lang.Boolean', common_pb2.BOOLEAN, None, None),
  121. ],
  122. 'string_value': [
  123. ('java.lang.Character', common_pb2.CHARACTER, None, None),
  124. ('java.lang.String', common_pb2.STRING, None, None),
  125. ('java.math.BigDecimal', common_pb2.BIG_DECIMAL, str, Decimal),
  126. ('java.sql.Array', common_pb2.ARRAY, None, None),
  127. ],
  128. 'number_value': [
  129. ('java.lang.Integer', common_pb2.INTEGER, None, int),
  130. ('java.lang.Short', common_pb2.SHORT, None, int),
  131. ('java.lang.Long', common_pb2.LONG, None, long if sys.version_info[0] < 3 else int),
  132. ('java.lang.Byte', common_pb2.BYTE, None, int),
  133. ('java.sql.Time', common_pb2.JAVA_SQL_TIME, time_to_java_sql_time, time_from_java_sql_time),
  134. ('java.sql.Date', common_pb2.JAVA_SQL_DATE, date_to_java_sql_date, date_from_java_sql_date),
  135. ('java.sql.Timestamp', common_pb2.JAVA_SQL_TIMESTAMP, datetime_to_java_sql_timestamp, datetime_from_java_sql_timestamp),
  136. ],
  137. 'bytes_value': [
  138. ('[B', common_pb2.BYTE_STRING, Binary, None),
  139. ],
  140. 'double_value': [
  141. # if common_pb2.FLOAT is used, incorrect values are sent
  142. ('java.lang.Float', common_pb2.DOUBLE, float, float),
  143. ('java.lang.Double', common_pb2.DOUBLE, float, float),
  144. ]
  145. }
  146. """Groups of Java classes."""
  147.  
  148. JAVA_CLASSES_MAP = dict( (v[0], (k, v[1], v[2], v[3])) for k in JAVA_CLASSES for v in JAVA_CLASSES[k] )
  149. """Flips the available types to allow for faster lookup by Java class.
  150.  
  151. This mapping should be structured as:
  152. {
  153. 'java.math.BigDecimal': ('string_value', common_pb2.BIG_DECIMAL, str, Decimal),),
  154. ...
  155. '<java class>': (<field_name>, <Rep enum>, <mutate_to function>, <cast_from function>),
  156. }
  157. """
  158.  
  159. class TypeHelper(object):
  160. @staticmethod
  161. def from_class(klass):
  162. """Retrieves a Rep and functions to cast to/from based on the Java class.
  163.  
  164. :param klass:
  165. The string of the Java class for the column or parameter.
  166.  
  167. :returns: tuple ``(field_name, rep, mutate_to, cast_from)``
  168. WHERE
  169. ``field_name`` is the attribute in ``common_pb2.TypedValue``
  170. ``rep`` is the common_pb2.Rep enum
  171. ``mutate_to`` is the function to cast values into Phoenix values, if any
  172. ``cast_from`` is the function to cast from the Phoenix value to the Python value, if any
  173.  
  174. :raises:
  175. NotImplementedError
  176. """
  177. if klass == 'org.apache.phoenix.schema.types.PhoenixArray':
  178. klass = "java.sql.Array"
  179. if klass not in JAVA_CLASSES_MAP:
  180. raise NotImplementedError('type {} is not supported'.format(klass))
  181.  
  182. return JAVA_CLASSES_MAP[klass]

改动后只支持 array里面的值是int、string例如 array(1,2,3),array('12','a','b')

phoenix 报错:type org.apache.phoenix.schema.types.PhoenixArray is not supported的更多相关文章

  1. phoenix启动报错:org.apache.phoenix.exception.PhoenixIOException: SYSTEM.CATALOG

    错误: org.apache.phoenix.exception.PhoenixIOException: SYSTEM.CATALOG at org.apache.phoenix.util.Serve ...

  2. 在DBeaver中phoenix查询报错:org.apache.phoenix.exception.PhoenixIOException: The system cannot find the path specified

    环境:Phoenix:4.4,win7系统 问题:Phoenix在查询hbase时,报"系统找不到指定路径". 解决: 请参见 https://distcp.quora.com/C ...

  3. Eclipse配置tomcat8.5.7报错:The Apache Tomcat installation at this directory is version 8.5.27. A Tomcat 8.0 installation is...

    Eclipse配置tomcat8.5.7报错:The Apache Tomcat installation at this directory is version 8.5.27. A Tomcat ...

  4. 【mybatis】mybatis访问报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 或者 feign被调用方使用的mybatis总报空指针异常java.lang.NullPointerException,而变量都没有问题的情况

    mybatis访问报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 需要检查的步骤: ...

  5. 【mybatis】mybatis方法访问报错:org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.pisen.cloud.luna.ms.goods.base.domain.GoodsConfigQuery

    在调用mapper.xml中的方法的时候,报错: org.apache.ibatis.builder.IncompleteElementException: Could not find result ...

  6. 启动项目报错:org.apache.catalina.LifecycleException: Failed to start component

    原因 环境异常重启,项目java进程未关闭,原项目的端口依旧在占用. 一般为8080端口被占用 解决方法 以下两种方法都可以解决,原理相同(结束异常进程) 1. 简单粗暴: 打开任务管理器找到java ...

  7. TOMCAT启动报错:org.apache.tomcat.jni.Error: 730055

    TOMCAT启动报错:org.apache.tomcat.jni.Error: 730055 具体原因:不清楚 解决方式:重启应用服务器后,再启动tomcat就可以了 欢迎关注公众号,学习kettle ...

  8. 使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法:

     使用IDEA操作Hbase API 报错:org.apache.hadoop.hbase.client.RetriesExhaustedException的解决方法: 1.错误详情: Excepti ...

  9. 通过phoenix创建hbase表失败,创建语句卡住,hbase-hmaster报错:exception=org.apache.hadoop.hbase.TableExistsException: SYNC_BUSINESS_INFO_BYDAY_EFFECT

    问题描述: 前几天一个同事来说,通过phoenix创建表失败了,一直报表存在的错误,删除也报错,然后就针对这个问题找下解决方案. 问题分析: 1.通过phoenix创建表,一直卡住不动了.创建语句如下 ...

随机推荐

  1. pycharm的快捷键

    一.编辑(Editing) Ctrl+Space 基本的代码完成(类.方法.属性) Ctrl+Alt+Space 快速导入任意类 Ctrl+Shift+Enter 语句完成 Ctrl+P 参数信息(在 ...

  2. kickstart文件制作与光盘镜像制作

    kickstart文件,是linux(Redhat.Centos.Fedora)下的anaconda安装程序的配置文件,基于此文件,可以实现linux的无人值守安装,在需要大规模部署安装linux的情 ...

  3. calcOpticalFlowPyrLK

    void calcOpticalFlowPyrLK( InputArray prevImg, InputArray nextImg,                                   ...

  4. JavaScript调用上下文(第九天)

    call与apply用法 使用哪个对象去调用相应的方法: var name="window"; var obj={ name:"obj" } function ...

  5. 微信小程序wx.navigateTo页面不跳转

    排查后发现: 若是在全局app.json中配置了tabBar,引用的链接与wx.navigateTo页面跳转url地址相同就无法实现跳转.

  6. 【缓存】介绍和使用场景 MEMCACHE REDIS

    缓存缓存就是在内存中存储的数据备份,当数据没有发生本质改变的时候,我们就不让数据的查询去数据库进行操作,而去内存中取数据,这样就大大降低了数据库的读写次数,而且从内存中读数据的速度比去数据库查询要快一 ...

  7. softmax 损失函数求导过程

    前言:softmax中的求导包含矩阵与向量的求导关系,记录的目的是为了回顾. 下图为利用softmax对样本进行k分类的问题,其损失函数的表达式为结构风险,第二项是模型结构的正则化项. 首先,每个qu ...

  8. TensorFlow机器学习实战指南之第二章

    一.计算图中的操作 在这个例子中,我们将结合前面所学的知识,传入一个列表到计算图中的操作,并打印返回值: 声明张量和占位符.这里,创建一个numpy数组,传入计算图操作: import tensorf ...

  9. layui 表格组件不能访问连续的属性的解决办法

    table.js里第741行改成这样,它这里只能访问一级属性// var content = item1[field]; 不能访问对象内的对象,比如item1.depart.name,只能访问一级属性 ...

  10. js求两个数组的交集|并集|差集|去重

    let a = [1,2,3], b= [2, 4, 5]; 1.差集 (a-b 差集:属于a但不属于b的集合)  a-b = [1,3] (b-a 差集:属于b但不属于a的集合)  b-a = [4 ...